Closed mrhoads closed 4 years ago
The first search result of that error message ModuleNotFoundError: No module named 'werkzeug.contrib'
leads me to this post created just 4 days ago. There are some discussion there too, speculating Flask issue or environment issue.
@mrhoads What version of these packages are you using?
CC @navyasric, @abhidnya13: Perhaps we can try and see if we can reproduce this in a clean environment. @abhidnya13 did you observe same issue during our tests in recent days? If not, there would be not much we can do here.
In a new virtualenv installing the requirements.txt I see: | Package | Version |
---|---|---|
certifi | 2019.11.28 | |
cffi | 1.14.0 | |
chardet | 3.0.4 | |
Click | 7.0 | |
cryptography | 2.8 | |
Flask | 1.1.1 | |
Flask-Session | 0.3.1 | |
idna | 2.8 | |
itsdangerous | 1.1.0 | |
Jinja2 | 2.11.1 | |
MarkupSafe | 1.1.1 | |
msal | 1.1.0 | |
pip | 20.0.2 | |
pycparser | 2.19 | |
PyJWT | 1.7.1 | |
requests | 2.22.0 | |
setuptools | 45.2.0 | |
six | 1.14.0 | |
urllib3 | 1.25.8 | |
Werkzeug | 1.0.0 | |
wheel | 0.34.2 |
Werkzeug 1.0.0 has removed deprecated code from 'werkzeug.contrib'. You can downgrade to Werkzeug 0.16.0 to work around this issue.
Thanks @daemonblade for the info! So this issue should be reported to our dependency, flask_session
, and, it happens to already have a duplicated issue there. Ideally this should also be fixed from there. We will close this issue here, soon.
@daemonblade downgrade works, thank 👍
I ran into the same issue when trying to use Proxyfix in werkzeug==1.0.0
After downgrading to werkzeug==0.16.0
, I got these warnings:
DeprecationWarning: 'werkzeug.contrib.fixers.ProxyFix' has moved to 'werkzeug.middleware.proxy_fix.ProxyFix'. This import is deprecated as of version 0.15 and will be removed in 1.0.
DeprecationWarning: 'werkzeug.contrib.cache' is deprecated as of version 0.15 and will be removed in version 1.0. It has moved to pallets. from werkzeug.contrib.cache import FileSystemCache
To fix the issues:
pip install werkzeug==1.0.0
For ProxyFix:
from werkzeug.middleware.proxy_fix import ProxyFix
For FileSystemCache, you will have to install pallets:
pip install -U cachelib
from cachelib.file import FileSystemCache
I hope this helps and fix your issues 😄
@Frost199 Dude, you are a life saver!
I am new to Linux and all the command lines that comes with it but am willing to learn!! Can you tell me what I am doing wrong here:
health@T3500:~/gnuhealth/tryton/server/trytond-5.0.18/bin $ python3 ./trytond-admin --all --database=health01
Traceback (most recent call last):
File "./trytond-admin", line 21, in
Thanks @Frost199 for the hint! With such root cause identified, we believe this issue in upstream repo will probably be fixed by this PR there.
Just in case someone comes around before the fix PR is merged, downgrade to version 0.6.1
I tried removing werkzeug version 1.0,.0 and installed werkzeug version 0.16.0 Typed in command ./trytond-admin --all --database=health01 = No output of what's going on and did not give me the option to add a password, Doing something in the background and just ended....
I will try to downgrade to version 0.6.1 and will let you guys know. Newbie to LINUX and Programming. THANK YOU FOR YOUR HELP!!!!!!!!
Thanks guys!!!!
I am having this issue too.
File "/home/zay/Python/tasks/venv/lib/python3.6/site-packages/Flask_Session-0.3.1-py3.6.egg/flask_session/sessions.py", line 313, in init from werkzeug.contrib.cache import FileSystemCache ModuleNotFoundError: No module named 'werkzeug.contrib'
pip list below click (7.1.1) Flask (1.1.1) Flask-Session (0.3.1) itsdangerous (1.1.0) Jinja2 (2.11.1) MarkupSafe (1.1.1) pip (9.0.1) pkg-resources (0.0.0) setuptools (39.0.1) Werkzeug (1.0.0)
I ran into the same issue when trying to use Proxyfix in
werkzeug==1.0.0
After downgrading to
werkzeug==0.16.0
, I got these warnings:
DeprecationWarning: 'werkzeug.contrib.fixers.ProxyFix' has moved to 'werkzeug.middleware.proxy_fix.ProxyFix'. This import is deprecated as of version 0.15 and will be removed in 1.0.
DeprecationWarning: 'werkzeug.contrib.cache' is deprecated as of version 0.15 and will be removed in version 1.0. It has moved to pallets. from werkzeug.contrib.cache import FileSystemCache
To fix the issues:
pip install werkzeug==1.0.0
For ProxyFix:
from werkzeug.middleware.proxy_fix import ProxyFix
For FileSystemCache, you will have to install pallets:
pip install -U cachelib
from cachelib.file import FileSystemCache
I hope this helps and fix your issues 😄
Thank you, this solution worked for me . I was struggling in that problem all for two days, thank you again.
@Frost199 , would you mind contact me and share how exactly you workaround this?
In particular, how did you use that from cachelib.file import FileSystemCache
? Did you have to patch that flask_session
too?
After installing cachelib
go to site-packages and change the session.py file
change "from werkzeug.contrib.cache import FileSystemCache" in line 313 to
"from cachelib.file import FileSystemCache"
@Alshafei2430 Thanks for the tip, but it did not work for me - the cachlib seems to be different...
I use Flask-Caching so I have used this import instead:
from flask_caching.backends.filesystem import FileSystemCache
Hi @filak , I also followed @Alshafei2430 's hint, and it worked, at least on my computerTM. :-)
Would you mind following step 2 of this pending PR to see if that workaround would work for you too? It would be helpful to have more people testing it, before we merge it in.
@rayluo I do not have the Azure tenant and it seems a bit complicated...
The cachelib FileSystemCache do not play well with Flask-session - it keeps resetting the session so I was not able to login. When using the module from flask_caching everything works as before.
@rayluo Same happens when I test it too as @filak
Hi guys, when executing "flask run" I receive the following error message: Error: While importing "application", an ImportError was raised:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
import(module_name)
File "/home/ubuntu/pset8/finance/application.py", line 9, in
I tried the hints provided in this thread but it just won't work. Quite sure I am doing something wrong but I just don't know what. Hope one of you guys can help me!
a lot can contribute to this, can you share your requirements.txt so we know the libraries that are dependent on werkzeug, it might be flask uploads, it might be something else, so we can not tell where the problem is from if this is all the information you are giving.
Of course @Frost199, totally right. Please find requirements.txt content attached.
from your attachment, you are using werkzeug==0.16.0, you shouldn't have such issues using with werkzeug.contrib as the first issue made by @mrhoads on this thread was fixed downgrading to 0.16.0, you might be doing something wrong and this error is only thrown if you are using werkzeug>=1.0
here is a screenshot from werkzeug changelog 1.0.x
or check out the link werkzeug changelog 1.0.x
First (pip or pip3): $ pip3 install werkzeug==1.0.0 $ pip3 install -U cachelib
Then, you need change in flask_session/sessions.py, around line 311: from werkzeug.contrib.cache import FileSystemCache for: from cachelib import FileSystemCache
@gottigjavier I've fixed this via #21.
If you are using an older version of this sample, or if you are working on your own project, you can follow this description to patch your environment, by:
pip uninstall flask-session
git+https://github.com/rayluo/flask-session@0.3.x#egg=flask-session
Hey everyone.
I found that the easiest way of dealing with this problem is by simply copying the contents of the FileSystemSessionInterface
, making a new version inside of your own project, and changing from werkzeug.contrib.cache import FileSystemCache
to from cachelib.file import FileSystemCache
.
I don't agree with the approach of modifying the contents of a package once it has been installed with pip install
. The reason being is that if you are deploying your Flask application to a platform such as Google App Engine, you won't be able to inject the aforementioned modifications once the runtime has installed all of your service's dependencies from the requirements.txt file.
Hopefully someone takes over this project or fixes the problem soon, but in the mean time, I found that was the best method for fixing this (if you're reliant on the filesystem implementation)!
Many thanks to @Frost199 for identifying where the missing reference now exists. :)
Hi @LoveDuckie , isn't this even easier?
pip uninstall flask-session
git+https://github.com/rayluo/flask-session@0.3.x#egg=flask-session
Specifically, it does not "modifying the contents of a package once it has been installed with pip install
". It just installs a workable version, technically still via pip install
.
@rayluo is git+https://github.com/rayluo/flask-session@0.3.x#egg=flask-session definable as a dependency under a generated requirements.txt
?
For example, can that be placed under all the other listings in a requirements.txt
file?
@LoveDuckie , you may not realize this. There are actually 2 different packages here:
flask-session
package hosted in PyPI.I'm one of the contributor of this web app sample, but I do NOT own that flask-session
. The best I can do, for now, is to provide a fix, hosted in my fork repo, and then have this web app sample to "use a github user's fork" - and that user happens to be me.
Feel free to make an educated decision on choosing whatever path you prefer.
I misunderstood that this issue was being raised on a completely unrelated sample code repository that you are a contributor of, and not the flask-session
repository. Regardless of good intentions I don't think it's a good idea to use someone else's GitHub fork as a dependency on a production service, irrespective of who that fork belongs to.
Good luck with taking over flask-session
. Thanks again for your efforts.
Thank you, downgrading to Werkzeug 0.16.0 from 1.0.0 worked!
Thank you so much for providing this answer! I was tearing my hair out over this issue!
In case anyone else is having this error, I changed
from werkzeug.contrib.profiler import ProfilerMiddleware
to
from werkzeug.middleware.profiler import ProfilerMiddleware
@Divide-By-0 , I suspect that you were brought to this thread by search engine based on keywords. But this issue and this repo are for a Web App sample for Microsoft identity platform, and we've fixed that issue in our sample 4 months ago.
I'll probably lock this conversation thread, to avoid future confusion on both sides.
I followed the steps in the tutorial; however, when attempting to run
python app.py
orflask run --port 5000
I received:I seemed to work around it by running
pip3 uninstall Werkzeug
followed bypip3 install Werkzeug==0.16.0
. That gets the app to run, though I don't know specifically why. I wanted to capture it in an issue and the workaround for others who might encounter this.