Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'cached_property' from 'werkzeug' #143

Open
bill-uncultured opened this issue Feb 6, 2020 · 31 comments
Open

cannot import name 'cached_property' from 'werkzeug' #143

bill-uncultured opened this issue Feb 6, 2020 · 31 comments

Comments

@bill-uncultured
Copy link

werkzeug just released 1.0.0, and the deprecated werkzeug.cached_property has been removed in favor of werkzeug.utils.cached_property.

This was addressed in October by pull request # 141, but it seems like it failed testing because the old python 3.3 and 2.6 couldn't be downloaded.

/usr/lib/python3.7/site-packages/flask_testing/__init__.py:13: in <module>
    from .utils import TestCase, LiveServerTestCase
/usr/lib/python3.7/site-packages/flask_testing/utils.py:35: in <module>
    from werkzeug import cached_property
E   ImportError: cannot import name 'cached_property' from 'werkzeug' (/usr/lib/python3.7/site-packages/werkzeug/__init__.py)
@teapow
Copy link

teapow commented Feb 7, 2020

Same issue as: noirbizarre/flask-restplus#777

The proposed temporary solution is to pin Werkzeug==0.16.1 until a proper fix is put in place.

@erodrig
Copy link

erodrig commented Feb 7, 2020

I have created a fix for this #144

but CI infrastructure is not working

Downloading archive: https://storage.googleapis.com/travis-ci-language-archives/python/binaries/ubuntu/16.04/x86_64/python-2.6.tar.bz2
0.10s$ curl -sSf --retry 5 -o python-2.6.tar.bz2 ${archive_url}
curl: (22) The requested URL returned error: 404 Not Found

oharsta added a commit to OpenConext/OpenConext-statistics that referenced this issue Feb 11, 2020
canihavesomecoffee added a commit to CCExtractor/sample-platform that referenced this issue Feb 12, 2020
Pin Werkzeug dependency to make sure unittests keep running while jarus/flask-testing#143 is still open.
@Ri1a
Copy link

Ri1a commented Feb 13, 2020

Another fix would be to edit the flask_testing/utils.py on line 35:
Use
from werkzeug.utils import cached_property
instead of
from werkzeug import cached_property

There's already a (closed) MR: #146

And an open one: #145

Edit: #145 has been merged

@elgohr
Copy link

elgohr commented Feb 19, 2020

Any updates regarding CI?

costolo added a commit to costolo/flask-docker that referenced this issue Feb 24, 2020
aadibajpai pushed a commit to SwagLyrics/SwagLyrics-For-Spotify that referenced this issue Feb 24, 2020
Pin Werkzeug dependency to make sure unittests keep running while jarus/flask-testing#143 is still open.
aadibajpai pushed a commit to SwagLyrics/SwagLyrics-For-Spotify that referenced this issue Feb 24, 2020
Pin Werkzeug dependency to make sure unittests keep running while jarus/flask-testing#143 is still open.
kshefchek added a commit to monarch-initiative/biolink-api that referenced this issue Feb 26, 2020
PhungXuanAnh added a commit to PhungXuanAnh/flask-restplus-boilerplate that referenced this issue Feb 27, 2020
PhungXuanAnh added a commit to PhungXuanAnh/flask-restplus-boilerplate that referenced this issue Feb 27, 2020
@Sispheor
Copy link

As it is fixed. Could you release a new version? :)

redimp pushed a commit to redimp/pyfounder that referenced this issue Feb 28, 2020
diaglab pushed a commit to cerndb/storage-api that referenced this issue Mar 6, 2020
diaglab pushed a commit to cerndb/storage-api that referenced this issue Mar 6, 2020
@Rahulrao0786
Copy link

from werkzeug import cached_property

ImportError: cannot import name 'cached_property' from 'werkzeug' (C:\Users\BABA\PycharmProjects\Automation\venv\lib\site-packages\werkzeug_init_.py)

I am getting this error message

@Rahulrao0786
Copy link

from flask import Flask
from flask_restplus import Api, Resource
from werkzeug.utils import *

app = Flask(name)
api = Api(app)

@api.route('/language')
class Language:
def get(self):
return {'hey': 'there'}

if name == "main":
app.run(debug=True)

beatthat added a commit to ICTLearningSciences/py-transcribe-aws that referenced this issue Mar 16, 2020
the explicit requirement for werkzeug should be removed one this issue is fixed:

jarus/flask-testing#143
beatthat added a commit to ICTLearningSciences/py-transcribe-aws that referenced this issue Mar 16, 2020
the explicit requirement for werkzeug should be removed one this issue is fixed:

jarus/flask-testing#143
@vicmunoz
Copy link

vicmunoz commented Mar 23, 2020

I've fixed this with:
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property

@KareenaR
Copy link

I've fixed this with:
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property

Thanks! This works.

@jnozsc
Copy link
Contributor

jnozsc commented Apr 12, 2020

fyi: this issue has been fixed in version 0.8.0

@evertoncastro
Copy link

Updating to Werkzeug==0.16.1 has fixed.

northkevin added a commit to northkevin/microservice-app that referenced this issue Apr 19, 2020
pomu0325 added a commit to pomu0325/pierre-decheck that referenced this issue Jun 22, 2020
pomu0325 added a commit to pomu0325/pierre-decheck that referenced this issue Jun 22, 2020
@felixminom
Copy link

Still happening when upgrading to 1.0.1 version

@philipperemy
Copy link

Still happening as of today.

@SidJain1412
Copy link

Still broken with werkzeug==1.0.1 as of 4th Sept 2020

Can be fixed by adding

import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property

before importing flask_restplus

aadibajpai added a commit to SwagLyrics/SwagLyrics-For-Spotify that referenced this issue Oct 17, 2020
Pin Werkzeug dependency to make sure unittests keep running while jarus/flask-testing#143 is still open.
@ctwardy
Copy link

ctwardy commented Dec 24, 2020

Thanks @SidJain1412!

User-side workaround when not expecting to call werkzeug directly:

try:
    from flask_restplus import Resource, Api
except ImportError:
    import werkzeug
    werkzeug.cached_property = werkzeug.utils.cached_property
    from flask_restplus import Resource, Api

@JosephHubbard
Copy link

This is still an issue.
My API backend still fails when using untampered Flask due to "cannot import name 'cached_property' from 'werkzeug'".

@bharath-kumarn
Copy link

bharath-kumarn commented Apr 20, 2021

This is still an issue.

ontology_1 | File "./get_title_details.py", line 1, in
ontology_1 | from robobrowser import RoboBrowser
ontology_1 | File "/usr/local/lib/python3.6/site-packages/robobrowser/init.py", line 3, in
ontology_1 | from .browser import RoboBrowser
ontology_1 | File "/usr/local/lib/python3.6/site-packages/robobrowser/browser.py", line 8, in
ontology_1 | from werkzeug import cached_property
ontology_1 | ImportError: cannot import name 'cached_property'

@paulakeen
Copy link

If I downgrade to Werkzeug==0.16.1 I get this other error:
from werkzeug.local import ContextVar
ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)

@ritesh-hubbler
Copy link

Werkzeug==2.0.1
Flask==2.0.1
flask-restplus==0.13.0

With this requirements, the issue is still there, I downgraded to
Werkzeug == 1.16.1 and downgraded other dependencies too... so it worked, but it should be working with latest version too, so please release a new version with this fix.

@rafael-andrade
Copy link

rafael-andrade commented Jun 7, 2021

Werkzeug==2.0.1
Flask==2.0.1
flask-restplus==0.13.0

With this requirements, the issue is still there, I downgraded to
Werkzeug == 1.16.1 and downgraded other dependencies too... so it worked, but it should be working with latest version too, so please release a new version with this fix.

When I downgrade it says: flask 2.0.1 requires Werkzeug>=2.0, but you'll have werkzeug 0.16.1 which is incompatible.. Any suggestions?

@ipam73
Copy link

ipam73 commented Jun 24, 2021

+1 Any ideas on how to resolve this? Haven't been able to solve the issue with the responses above and downgrading is not an option due to flask 2.0.1 not being compatible.

Flask==2.0.1
Flask-RESTful==0.3.9
Flask-Testing==0.7.1
Werkzeug==2.0.1

Traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/unittest/loader.py", line 434, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/lib/python3.7/unittest/loader.py", line 375, in _get_module_from_name
    __import__(name)
  File "/usr/src/app/project/tests/test_account_model.py", line 6, in <module>
    from project.tests.base import BaseTestCase
  File "/usr/src/app/project/tests/base.py", line 4, in <module>
    from flask_testing import TestCase
  File "/usr/local/lib/python3.7/site-packages/flask_testing/__init__.py", line 13, in <module>
    from .utils import TestCase, LiveServerTestCase
  File "/usr/local/lib/python3.7/site-packages/flask_testing/utils.py", line 35, in <module>
    from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/usr/local/lib/python3.7/site-packages/werkzeug/__init__.py)

@toddman2
Copy link

If I downgrade to Werkzeug==0.16.1 I get this other error:
from werkzeug.local import ContextVar
ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)

100%. I can't believe this is still going on.

@bharath-kumarn
Copy link

bharath-kumarn commented Jul 13, 2021 via email

@palmettobugz
Copy link

Maybe related: Switch locals to be based on ContextVars #1778
https://github.com/pallets/werkzeug/pull/1778

pgjones commented on Mar 28, 2020 •
ContextVar was introduced in Python 3.7 and is effectively the same as Local in Werkzeug (although a different API). They should work in Greenlet and threading contexts as before but also now in asyncio or other async/await contexts.

The storage attribute has been kept for backwards compatibility (even though it is a dunder it seems it is used, e.g. in tests).

The ident_func though must be deprecated as this is now handled by the ContextVar. This may cause some backwards incompatibility.

sierra-moxon added a commit to geneontology/biolink-api that referenced this issue Aug 2, 2021
@4vadim4
Copy link

4vadim4 commented Sep 16, 2021

Is there a solution to this problem?
Because the first mention with Flask==2.0.1, flask-restplus==0.13.0, Werkzeug==2.0.1 was in June.
This bug has yet to be resolved?

@Ninthpool
Copy link

Ninthpool commented Jan 27, 2022

The issue still persists as of today... temporary workaround:

try: 
    from flask_restplus import Api, Resource
except ImportError:
    import werkzeug, flask.scaffold
    werkzeug.cached_property = werkzeug.utils.cached_property
    flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
    from flask_restplus import Api, Resource

@vikramadhav
Copy link

Current requirements.txt

Flask==2.1.2
Flask-Assets==2.0
flask-restplus==0.13.0
Werkzeug==2.1.2

and applied work around as (Downgrade is not possible due to compatibility)

try: 
    from flask_restplus import Api, Resource,Namespace
except ImportError:
    import werkzeug, flask.scaffold
    werkzeug.cached_property = werkzeug.utils.cached_property
    flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
    from flask_restplus import Api, Resource,Namespace
    
from models.hello_world import helloWork

data_edits_namespce=Namespace('data_edits')

data_edits_namespce.add_model('HelloWorld',helloWork)

Now the exception is coming

from flask_restplus import Api, Resource,Namespace
venv/lib/python3.10/site-packages/flask_restplus/model.py", line 8, in <module> from collections import OrderedDict, MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

Not sure what i am missing here , does any one else also faced same issue

@felixminom
Copy link

We all should be migrating to flask-restx which is a wrapper for this library and it's been actively maintained.

@toddman2
Copy link

Clearly seems the owner is busy these days or no longer has an interest in fixing this. I'm cutting the guy some slack -- it's been a useful package so far. It would be appreciated if he could check in with us one way or another. Thanks for all your time you've put into so far.

@fauber5
Copy link

fauber5 commented Jun 15, 2023

"
#0 370.1 ERROR: Cannot install -r requirements.txt (line 32) and Werkzeug==0.16.1 because these package versions have conflicting dependencies.
#0 370.1
#0 370.1 The conflict is caused by:
#0 370.1 The user requested Werkzeug==0.16.1
#0 370.1 flask 2.0.2 depends on Werkzeug>=2.0

The temporary solution isn't possible. "pin Werkzeug==0.16.1 until a proper fix is put in place."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests