Questions with six under django?

I am trying to use a package called vcrpy to speed up the execution of my Django application test suite. I am 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'): 

As a result, an import error occurs:

  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 problem code in the VCR package itself:

 import six from six.moves.http_client import ( HTTPConnection, HTTPSConnection, HTTPMessage, HTTPResponse, ) 

The funny thing is: this code works fine when I just run it from a simple python console, but it leads to the ImportError described above in Django or under the django manage.py shell.

Any idea what could be wrong?

(some additional information about the location of the six modules:

When I run the empty 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 with import django; django.setup() import django; django.setup() , from manage.py shell leads to exactly the same directory and the same six.pyc file.

)

+6
source share
3 answers

It may be too late for the original question, but I came here via Google, so for future reference, here is my solution:

Problem

The problem I discovered is that mac os comes with not only python, but also some packages pre-installed. Six is ​​one of these packages, and that is the conflict. Preset six take precedence over a peak set by six, but pip still provides information based on what it installed (for example, six 1.9.0 versus 1.4.1).

pre-installed (version 1.4.1):

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/

pip is installed (no matter what you installed, for me it was 1.9.0):

/Library/Python/2.7/site-packages/

You can check if this works for you:

 $ python >>> import six >>> print six.__file__ '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py' 

Fixation

The solution is actually quite simple, just put

export PYTHONPATH="/Library/Python/2.7/site-packages:$PYTHONPATH"

in your ~/.bashrc (or any other file that your shell uses). If you configured your pip to install somewhere else, put this in the pythonpath.

+9
source

I had a similar problem on Fedora 21. The reason for this was the 2 installed version of six 1.2.0 and 1.9.0 . I solved this problem by uninstalling six and reinstalling the latest version:

 pip uninstall six pip install six 
+1
source

Sounds like a conflict with multiple versions. I solved a similar error by downgrading my version from six (1.9.0 caused an error, like 1.8.0 and 1.7.0). 1.6.0 works without errors.

The error I was getting: from six.moves import http_client ImportError: not a single module named move

0
source

Source: https://habr.com/ru/post/980165/


All Articles