Python3 'Cannot import name 'cached_property'

Viewed 22125

I cannot get this to work. I keep adding modules and there's a new one not found each time. Why doesn't this code work in Python3.6?

Code:

from robobrowser import robobrowser
from bs4 import BeautifulSoup
import urllib2 
import cookielib
from werkzeug import werkzeug
from cached_property import cached_property

cj = cookielib.CookieJar()
br = robobrowser.Browser()
br.set_cookiejar(cj)
br.open("https://www.cbssports.com/login")

br.select_form(nr=0)
br.form['userid'] = 'steveb1164'
br.form['password'] = ''
br.submit()

print(br.response().read())

Run:

RESTART: C:/Users/Steve/AppData/Local/Programs/Python/Python36-32/CBSlogin.py 
Traceback (most recent call last):
  File "C:/Users/Steve/AppData/Local/Programs/Python/Python36-32/CBSlogin.py", line 1, in <module>
    from robobrowser import robobrowser
  File "C:\Users\Steve\AppData\Local\Programs\Python\Python36-32\lib\site-packages\robobrowser\robobrowser\__init__.py", line 3, in <module>
    from .browser import RoboBrowser
  File "C:\Users\Steve\AppData\Local\Programs\Python\Python36-32\lib\site-packages\robobrowser\robobrowser\browser.py", line 8, in <module>
    from werkzeug import cached_property
ImportError: cannot import name 'cached_property'
6 Answers

I got the werkzeug app running in Python 3.6 by inserting those lines before the Flask importing:

import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property

A bit of a late response, but I may have found a solution.

You need to rename from werkzeug import cached property to the following:

from werkzeug.utils import cached_property

Hope this helps!

  1. Uninstall the werkzeug package by running - pip uninstall werkzeug
  2. Reinstall the werkzeug package by running - pip install werkzeug
  3. Add import werkzeug werkzeug.cached_property = werkzeug.utils.cached_property this to your code.

I hope its gonna work, cause it just worked for me.

I got the same issue. My python version is 3.7.3 and was using Werkzeug version 1.0.1

I downgraded the Werkzeug version to 0.16.0 and it worked

pip install --upgrade Werkzeug==0.16.0

Try reinstalling the werkzeug package.

pip uninstall Werkzeug
pip install Werkzeug
Related