2

I'm having a problem similar to this post, but I am already running the latest version of virtualenv and I also get a different ImportError.

Using virtualenv with version 2.7 (default) works fine but I need to use python3 for another project. I installed it using brew install python3 in OSX 10.10.2.

When I try:

> pip install --upgrade virtualenv
Requirement already up-to-date: virtualenv in /Library/Python/2.7/site-packages
Cleaning up...

> virtualenv --version
12.0.7

> virtualenv -p python3 test

I still get:

Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Failed to import the site module
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 73, in <module>
    __boot()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 2, in __boot
    import sys, imp, os, os.path   
  File "/Users/user/Desktop/project/studyprocessor/venv/bin/../lib/python3.4/imp.py", line 22, in <module>
    from importlib import util
  File "/Users/user/Desktop/project/studyprocessor/venv/bin/../lib/python3.4/importlib/util.py", line 12, in <module>
    from contextlib import contextmanager
ImportError: No module named 'contextlib'
ERROR: The executable venv/bin/python3.4 is not functioning
ERROR: It thinks sys.prefix is '/Users/user/Desktop/project/studyprocessor' (should be '/Users/user/Desktop/project/studyprocessor/venv')
ERROR: virtualenv is not compatible with this system or executable

Any ideas?

Community
  • 1
  • 1
OpenUserX03
  • 1,448
  • 2
  • 14
  • 21

2 Answers2

4

The pip program what you are using corresponds to the Python 2.7 version. You need to use the pip which corresponds to Python 3.x. So, you should be using

pip3 install virtualenv

Alternatively, you can create virtual environments in Python 3.3+ with the venv module, like this

python3 -m venv test
thefourtheye
  • 233,700
  • 52
  • 457
  • 497
0

try following

virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3

workon py3
Dadaso Zanzane
  • 6,039
  • 1
  • 25
  • 25
  • 1
    While this answer may be correct, please add some explanation. Imparting the underlying logic is more important than just giving the code, because it helps the OP and other readers fix this and similar issues themselves. – CodeMouse92 Oct 10 '15 at 01:04