Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtualenv and Anaconda issues

So this issue has been brought up before, but I have not found a proper solution to this.

I'm on a mac. When I run python in terminal I get:

Python 2.7.6 |Anaconda 1.9.2 (x86_64)| (default, Jan 10 2014, 11:23:15) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

I don't really understand what that means, is it running Python 2.7.6 with Anaconda?

Anyways, my problem is that I can't setup a virtualenv. When I try to create a virtual environment I get this error message:

New python executable in virtualenvs/bin/python
Installing setuptools, pip...
  Complete output from command /Users/arashsaidi/virtualenvs/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
  Ignoring indexes: https://pypi.python.org/simple/
Exception:
Traceback (most recent call last):
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/commands/install.py", line 236, in run
    session = self._build_session(options)
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/basecommand.py", line 52, in _build_session
    session = PipSession()
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/download.py", line 216, in __init__
    super(PipSession, self).__init__(*args, **kwargs)
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 273, in __init__
    self.headers = default_headers()
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/requests/utils.py", line 555, in default_headers
    'User-Agent': default_user_agent(),
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/requests/utils.py", line 524, in default_user_agent
    _implementation = platform.python_implementation()
  File "/Users/arashsaidi/anaconda/lib/python2.7/platform.py", line 1499, in python_implementation
    return _sys_version()[0]
  File "/Users/arashsaidi/anaconda/lib/python2.7/platform.py", line 1464, in _sys_version
    repr(sys_version))
ValueError: failed to parse CPython sys.version: '2.7.5 (default, Aug 25 2013, 00:04:04) \n[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]'

Storing debug log for failure in /var/folders/jg/hs6w4q8x10n4ycwwf06dnp440000gn/T/tmpmM9rRS
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "/Users/arashsaidi/anaconda/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv.py", line 824, in main
    symlink=options.symlink)
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv.py", line 992, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv.py", line 960, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/Users/arashsaidi/anaconda/lib/python2.7/site-packages/virtualenv.py", line 902, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/arashsaidi/virtualenvs/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 2

Could you help me find a solution?

like image 525
Arash Saidi Avatar asked May 22 '14 11:05

Arash Saidi


4 Answers

The virtualenv package does not work with Anaconda. From the terminal prompt you should create a new virtual environment using the conda statement conda -n new_env_name, as is explained in the docs.

like image 106
Remco Coumou Avatar answered Oct 16 '22 08:10

Remco Coumou


Having anaconda on my Ubuntu15.10 is nice, but using virtualenv/virtualenvwrapper/pyvenv to create virtual environment on top of that is "ISIBDWYHI"

Here is my way. 1. comment out # export PATH="/your/path/to/anaconda3/bin:$PATH" from ~/.bashrc 2. restart a terminal and create virtual environment wherever you want. 3. make export PATH="/your/path/to/anaconda3/bin:$PATH" back.

like image 42
F.wo.huang Avatar answered Oct 16 '22 08:10

F.wo.huang


The issue OP has is really that he has multiple versions of python and in his system PATH the anaconda python came out first. He was trying to use virtualenv within his conda environment, so that's why he got error. He can actually have both regular python (w/ virtualenv) and anaconda python install together, and as long as he knows which python is which, he can still run virtualenv with his regular python.

like image 1
AnthonyC Avatar answered Oct 16 '22 08:10

AnthonyC


Anaconda Python can work with virtualenvs so long as you install the virtualenv package via conda. Use --force-reinstall to be sure.

conda install --force-reinstall virtualenv
like image 1
rjurney Avatar answered Oct 16 '22 10:10

rjurney