Virtualenv: [Mac] Trying to create a python virtual environment but getting OSError

Created on 25 Aug 2015  ·  22Comments  ·  Source: pypa/virtualenv

Mac OS X: 10.9.5
pip 7.1.2
virtualenv 13.1.2
Python: Python 2.7.10 :: Anaconda 2.3.0 (x86_64)

Shuais-MacBook-Pro:Google Drive shuaiwang$ virtualenv ENV
New python executable in ENV/bin/python
Installing setuptools, pip, wheel...
Complete output from command "/Users/shuaiwang/Google Drive/ENV/bin/python" -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Traceback (most recent call last):
File "", line 1, in
File "/Users/shuaiwang/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/init.py", line 13, in
File "/Users/shuaiwang/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/utils/init.py", line 15, in
File "/Users/shuaiwang/anaconda/lib/python2.7/zipfile.py", line 6, in
import io
File "/Users/shuaiwang/anaconda/lib/python2.7/io.py", line 51, in
import _io
ImportError: dlopen(/Users/shuaiwang/Google Drive/ENV/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /Users/shuaiwang/Google Drive/ENV/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup


...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/Users/shuaiwang/anaconda/bin/virtualenv", line 11, in
sys.exit(main())
File "/Users/shuaiwang/anaconda/lib/python2.7/site-packages/virtualenv.py", line 832, in main
symlink=options.symlink)
File "/Users/shuaiwang/anaconda/lib/python2.7/site-packages/virtualenv.py", line 1004, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Users/shuaiwang/anaconda/lib/python2.7/site-packages/virtualenv.py", line 969, in install_wheel
'PIP_NO_INDEX': '1'
File "/Users/shuaiwang/anaconda/lib/python2.7/site-packages/virtualenv.py", line 910, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command "/Users/shuaiwang/Google Drive/ENV/bin/python" -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1

Most helpful comment

I had a similar issue with conda and virtualenv. I was able to successfully install and activate an env with the following command:
conda install -c anaconda virtualenv=15.1.0

All 22 comments

I have the exact same error, and I'm using a very similar set up:

  • Mac 10.10.3
  • pip 7.1.2
  • virtualenv 13.0.1
  • Python 2.7.10 :: Anaconda 2.2.0 (x86_64)

This is a possible duplicate of https://github.com/pypa/virtualenv/issues/788

@grisaitis #788 is a duplicate of #788? :D

And yes, at the moment this looks like a conda python issue.

Oops! Sorry, I meant it could be a duplicate of this: https://github.com/pypa/virtualenv/issues/741

And this is "fixed" by downgrading to Python 2.7.9, in case you didn't see in https://github.com/conda/conda/issues/1367

Actually, it is not fixed (and I am aware that this is probably a condo/virtualenv co-issue).

I have the same problems with Python 2.7.11 and Python 3.5.1 and conda 3.18.9 (and pip 7.1.2).
With Python 3.5.1, virtual environment creation fails with "virtualenv" and "pyvenv" (with a slightly different error).

@jenisys please could you paste the actual error?

With a conda environment based on python 2.7.11 and virtualenv 13.0.1, I get the similar error that was described above (but another CPython symbol is missing now);

# -- CASE: Using conda environment "py27" with python 2.7.11
# INSTALLED: virtualenv 13.0.1, pip 7.1.2, wheel 0.26.0
$ virtualenv xxx
New python executable in xxx/bin/python
Installing setuptools, pip, wheel...
  Complete output from command /Users/alice/tmp/venv/xxx/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/alice/conda/envs/py27/lib/python2.7/site-packages/virtualenv_support/pip-7.0.1-py2.py3-none-any.whl/pip/__init__.py", line 13, in <module>
  File "/Users/alice/conda/envs/py27/lib/python2.7/site-packages/virtualenv_support/pip-7.0.1-py2.py3-none-any.whl/pip/utils/__init__.py", line 15, in <module>
  File "/Users/alice/conda/envs/py27/lib/python2.7/zipfile.py", line 6, in <module>
    import io
  File "/Users/alice/conda/envs/py27/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/Users/alice/tmp/venv/xxx/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /Users/alice/tmp/venv/xxx/lib/python2.7/lib-dynload/_io.so
  Expected in: dynamic lookup

----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/Users/alice/conda/envs/py27/bin/virtualenv", line 6, in <module>
    sys.exit(main())
  File "/Users/alice/conda/envs/py27/lib/python2.7/site-packages/virtualenv.py", line 832, in main
    symlink=options.symlink)
  File "/Users/alice/conda/envs/py27/lib/python2.7/site-packages/virtualenv.py", line 1004, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/Users/alice/conda/envs/py27/lib/python2.7/site-packages/virtualenv.py", line 969, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/Users/alice/conda/envs/py27/lib/python2.7/site-packages/virtualenv.py", line 910, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/alice/tmp/venv/xxx/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1

With a conda environment with python 3.5.1, the error looks slightly different:

# -- CASE: Using conda environment "py35" with python 3.5.1
# INSTALLED: virtualenv 13.1.2, pip 7.1.2, wheel 0.26.0
$ virtualenv --verbose xxx2
Using base prefix '/Users/alice/conda/envs/py35'
Creating xxx2/lib/python3.5
Symlinking Python bootstrap modules
  Symlinking xxx2/lib/python3.5/config-3.5m
  Symlinking xxx2/lib/python3.5/lib-dynload
  Symlinking xxx2/lib/python3.5/plat-darwin
  Symlinking xxx2/lib/python3.5/os.py
  ...
  Symlinking xxx2/lib/python3.5/_bootlocale.py
Creating xxx2/lib/python3.5/site-packages
Writing xxx2/lib/python3.5/site.py
Writing xxx2/lib/python3.5/orig-prefix.txt
Writing xxx2/lib/python3.5/no-global-site-packages.txt
Creating parent directories for xxx2/include
Symlinking xxx2/include/python3.5m
Creating xxx2/bin
New python executable in xxx2/bin/python3
Changed mode of xxx2/bin/python3 to 0o755
Also creating executable in xxx2/bin/python
Changed mode of xxx2/bin/python to 0o755
Testing executable with xxx2/bin/python3 -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
ERROR: The executable xxx2/bin/python3 is not functioning
ERROR: It thinks sys.prefix is '/Users/alice/tmp/venv' (should be '/Users/alice/tmp/venv/xxx2')
ERROR: virtualenv is not compatible with this system or executable

When I use pyvenv in the conda environment (as expected with Python 3.x), I get another error related to the missing "ensure pip" module (conda internal problem, I assume).

I have the same issue here, can someone point me the solution for this issue? Since it's closed, must be solved right?

@icrtiou It's closed here because it's a conda issue (the issue number is noted above). Doesn't look like it's fixed there yet, but you should review the conda ticket for further information.

I've ran into a similar error (not using anaconda, installed python using brew install) when I was trying to recreate an env without first deleting the previous env.

after rm -rf of the old env path, the error was solved...

I had a similar issue with conda and virtualenv. I was able to successfully install and activate an env with the following command:
conda install -c anaconda virtualenv=15.1.0

Thank you!! That worked for me.

my solution is change the default python and pip to /user/bin/python instead of conda version
NOTE: after first conda error virtualenvs folder is already created and stored conda's path and setup, so need to remove that folder first before creating a new virtualenvs folder

rm -rf .virtualenvs/ # remove
source virtualenvwrapper.sh # create bew virtualenvs

The solution proposed by @RubenDuran worked for me.

I wasn't using anaconda and was running into this. Just trying to use pyenv and virtualenvwrapper. I swear this had worked before but I was running this to create a new virtualenv:

pyenv shell 3.6.3
mkvirtualenv my_new_env

That would yield a similar stack trace to those above. To fix it, I installed pyenv-virtualenvwrapper. Then the following is how I got it to work:

pyenv shell 3.6.3
pyenv virtualenvwrapper
mkvirtualenv my_new_env

Not totally sure what happened but it's working and thought I'd share in case anyone else was running into a similar issue.

@RubenDuran you are a superstar! You solution worked perfectly for me.

@RubenDuran thanks a bunch!

Again @RubenDuran solution worked! Thanks!!!

Solution to create the virtual environment for your project if you have conda. I had a similar issue, I tried the following command and it worked for me.
Ubuntu 16.04
Python 2.7.14 :: Anaconda, Inc.

conda create -n yourenvname python=x.x anaconda

_yourenvname_ is the name of the virtual environment that you are going to create and use.
_pyrhon=x.x_: pick the version of python you want to use in this environment

Hi,
I'm facing to the same situation on centos 7. I fixed the problem with the following lines:

yum install epel-release

yum install python-pip

pip install -U pip

yum -y install python-virtualenv

yum -y install python-virtualenvwrapper

$ export WORKON_HOME=~/.virtualenvs
$ source /usr/bin/virtualenvwrapper.sh
$ mkvirtualenv myapp
$ deactivate
$ workon myapp

Was this page helpful?
0 / 5 - 0 ratings