beaker
beaker copied to clipboard
Python 2.7 CacheManager | ImportError: cannot import name http_cookies
I use Flask-Beaker, which depends on beaker. Flask-Beaker does not specify a beaker version, and I recently ran in to issues with the beaker it installed. I am also running python v2.7.10.
Traceback (most recent call last):
File "bin.py", line 11, in <module>
from api import create_api
File "./api.py", line 6, in <module>
import containers.Provisioner as Provisioner
File "./containers/Provisioner.py", line 13, in <module>
from beaker.cache import CacheManager
File "/home/weebyman/manager/server/env/local/lib/python2.7/site-packages/beaker/cache.py", line 12, in <module>
from beaker._compat import u_, unicode_text, func_signature, bindfuncargs
File "/home/weebyman/manager/server/env/local/lib/python2.7/site-packages/beaker/_compat.py", line 65, in <module>
import Cookie as http_cookies
File "/home/weebyman/manager/server/env/local/lib/python2.7/site-packages/beaker/Cookie.py", line 2, in <module>
from ._compat import http_cookies
ImportError: cannot import name http_cookies
This lead me to: https://github.com/bbangert/beaker/blob/master/beaker/_compat.py#L65
Which appears to be a circular import.
Temporary fix: add to requirements.txt:
beaker==1.7.0
run pip install -r requirements.txt
again:
Installing collected packages: beaker
Found existing installation: Beaker 1.8.0
Uninstalling Beaker-1.8.0:
Successfully uninstalled Beaker-1.8.0
Successfully installed beaker-1.7.0
Uh, there is no such file as Cookie.py
in beaker, there is a cookie.py
and imports are case sensitive (or at least case preserving). What's your file system? There shouldn't be any Cookie.py
file and it's working as expected for me and on travis
How odd... Looking at the lower case cookie file I am seeing: https://github.com/bbangert/beaker/blob/master/beaker/cookie.py#L2 which seems to be the circular import in question.
I am running on ubuntu. The filesystem is an nfs mount on ubuntu (case sensitive) hosted by an osx machine (case insensitive). Could be some issue there, I suppose.
The line import Cookie as http_cookies
is supposed to be importing the standard library cookie?
Yes, import Cookie
should import the Cookie
module from standard library, not the local cookie.py
.
As you are mounting the NFS from an HFS+ formatted as case insensitive the lookup for the file succeeds on cookie.py
and so the wrong module ends up being imported.
I think I can work that around using from __future__ import absolute_import
but it might still be happening somewhere else and I'm not really able to test it as all my systems are case sensitive.
I saw the same thing working in a vm which is nfs-mounting from a case-insensitive hfs+ host os. cookie.py
is the only place I saw it happen.
I saw this issue when working in a vagrant / virtualbox vm over an OSX host where the git workspace was mounted in the guest from the host fs.
I'm also encountering this issue with a similar setup to @stevelle. This basically means that beaker is no longer compatible with OSX machines or OSX filesystems, as far as I can tell.
@tedivm It's only incompatible when the file system is formatted in case insensitive mode. My primary development machine is an OSX system and beaker works fine there as the system is case sensitive.
https://github.com/bbangert/beaker/commit/3edfd85adce2c32bc7059d64a40a80ef809ec9e8 should fix this for case insensitive systems too, but I couldn't try it as I have no case insensitive system available and Travis currently doesn't support Python on OSX ( https://github.com/travis-ci/travis-ci/issues/4729 ). If anyone can try master
on a system where the error was replicable and confirm it's now fixed it would greatly help to speed up a release.