Reputation: 12503
I'm trying to use a package called vcrpy to accelerate the execution of my django application test suite. I'm using django 1.7 on Mac, with Python 2.7.
I added the following couple of lines to one of my tests:
import vcr
with vcr.use_cassette('recording.yaml'):
The result is an import error:
import vcr
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/__init__.py", line 2, in <module>
from .config import VCR
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/config.py", line 6, in <module>
from .cassette import Cassette
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/cassette.py", line 12, in <module>
from .patch import CassettePatcherBuilder
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/patch.py", line 8, in <module>
from .stubs import VCRHTTPConnection, VCRHTTPSConnection
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vcr/stubs/__init__.py", line 9, in <module>
from six.moves.http_client import (
ImportError: No module named http_client
The problematic code in the VCR package itself is:
import six
from six.moves.http_client import (
HTTPConnection,
HTTPSConnection,
HTTPMessage,
HTTPResponse,
)
The funny thing: this code seems to run fine when I'm just running it from a plain python console, but it results in the above ImportError under Django or under the django manage.py shell.
Any idea what might be wrong?
( some additional details about the location of the six module:
When I'm running plain python console, I get the following:
Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import six
>>> print six.__file__
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.pyc
Doing the same thing, with import django; django.setup()
, from manage.py shell
results in exactly the same directory and same six.pyc file.
)
Upvotes: 6
Views: 4646
Reputation: 96
I had a similar problem on Fedora 21. The reason for this was 2 installed version of the six 1.2.0 and 1.9.0
. I solved this problem by the uninstall six
, and re-installation latest version:
pip uninstall six
pip install six
Upvotes: 1
Reputation: 1344
Maybe a little bit too late for the original question, but I came here trough Google so for future reference, here's my solution:
The problem I found is that mac os comes with not only python but also some packages pre-installed. Six is one of those packages and therein lies the conflict. The pre-installed six takes priority over the pip installed six, but pip still gives information based on what it itself has installed (e.g. six 1.9.0 vs 1.4.1).
pre-installed (version 1.4.1):
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/
pip installed (whatever you have installed, for me it was 1.9.0):
/Library/Python/2.7/site-packages/
You can check if this is the case for you by running:
$ python
>>> import six
>>> print six.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py'
The solution is actually quite simple, just put
export PYTHONPATH="/Library/Python/2.7/site-packages:$PYTHONPATH"
in your ~/.bashrc
(or whatever file your shell uses). If you've configured your pip to install somewhere else, put that in the pythonpath instead.
Upvotes: 9
Reputation: 1
Sounds like a multiple-versions conflict. I solved a similar error by downgrading my version of six (1.9.0 caused the error, as did 1.8.0 and 1.7.0). 1.6.0 works without error.
The error I was getting: from six.moves import http_client ImportError: No module named moves
Upvotes: 0