2

I have installed Python 3.5 through Anaconda on the OSX system. After installing and activating the virtual environment,

virtualenv venv
source venv/bin/activate

The Python version is Python 2.7.10. And while we are allowed to load the interpreter of our choice in virtualenv, "/usr/bin/" only has folders for Python 2.6 and 2.7. After finding out the Anaconda python 3.5 path ( /Users/Username/anaconda/lib/python3.5) and trying to load it,

for: virtualenv -p /Users/Username/anaconda/lib/python3.5 venv

the code returns a [Errno 13] Permission Denied

> Running virtualenv with interpreter /Users/Username/anaconda/lib/python3.5
> Traceback (most recent call last):   File "/usr/local/bin/virtualenv",
> line 11, in <module>
>     sys.exit(main())   File "/Library/Python/2.7/site-packages/virtualenv.py", line 790, in main
>     popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
> line 710, in __init__
>     errread, errwrite)   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
> line 1335, in _execute_child
>     raise child_exception
OSError: [Errno 13] Permission denied

for: virtualenv -p /Users/Username/anaconda/bin/python3.5 venv

there seems to be another type of error...

Running virtualenv with interpreter /Users/Username/anaconda/bin/python3.5
Using base prefix '/Users/Username/anaconda'
New python executable in venv/bin/python3.5
Not overwriting existing python script venv/bin/python (you must use venv/bin/python3.5)
ERROR: The executable venv/bin/python3.5 is not functioning
ERROR: It thinks sys.prefix is '/Users/Username/.../targetfolder' (should be '/Users/Username/.../targetfolder/venv')
ERROR: virtualenv is not compatible with this system or executable
5
  • You could use the -p option to specify the path to Anaconda's Python 3 interpreter. Commented Sep 22, 2016 at 4:24
  • anaconda's python is usually automatically found, at least on ubuntu. when outside the virtualenv, does python use the anaconda python? Commented Sep 22, 2016 at 4:26
  • yes, when outside of virtualenv it uses the Python 3.5. but still figuring out how to load it into virtualenv... Commented Sep 22, 2016 at 4:31
  • 1
    Try bin/python3.5 instead of lib/python3.5 ? Commented Sep 22, 2016 at 5:05
  • Thanks! now the permission error disappears but another error seems to emerge, please see my updated question for more information Commented Sep 22, 2016 at 5:14

1 Answer 1

3
ERROR: The executable venv/bin/python3.5 is not functioning
ERROR: It thinks sys.prefix is '/Users/Username/.../targetfolder' (should be '/Users/Username/.../targetfolder/venv')
ERROR: virtualenv is not compatible with this system or executable

This error results from trying to combine incompatible versions of Python and the virtualenv tool. I'm not sure precisely where the incompatibility comes from, but I do know how to work around it.

Assuming your Python is reasonably functional and recent (read: 3.3 or later), this should always work:

/path/to/python3.5 -m venv venv

The first venv is the venv module. The second is the name of the directory where you want to create a virtualenv. This command asks Python to create a virtualenv itself, rather than shelling out to a third-party tool. Thus, we can be reasonably confident Python will do it correctly, and in particular that it will not be incompatible with itself.


Unfortunately, the version of Python installed with Anaconda cannot be described as "reasonably functional" because it lacks ensurepip. That makes it impossible for the venv module to bootstrap pip into your virtualenv. So you will need to build your venv without pip, and then install it manually:

/path/to/python3.5 -m venv --without-pip venv

Then download and run get-pip.py from within the virtualenv.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! As stated I am on Python 3.5 so should have worked... below are the outputs though: Unable to symlink '/Users/Username/anaconda/bin/python3.5' to '/Users/targetfolder/venv/bin/python3.5', Error: Command '['targetpath/venv/bin/python3.5', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status -11
Try it with the --copies flag? If that fails, you might have to use --without-pip, which is rather inconvenient.
thanks! can you elaborate a bit more? is /path/to/python3.5 -m venv venv --copies what you mean?
That will probably work but pedantically it should be after the module name and before the target directory name (so -m venv --copies venv). Also, if the target directory already exists (because you did not clean it up after a previous run), you must pass the --clear flag to tell the venv module to remove the existing cruft.
thanks so much for the instructions! didn't expect that Anaconda python can be this tricky and some steps need to be taken. all issues can be resolved using the method provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.