尝试打开虚拟环境时出现错误

时间:2019-06-28 22:58:29

标签: python virtualenv

尝试遵循我理解的最佳实践,我安装了virtualenv以便能够在本地安装python模块(并且不会破坏任何其他程序或依赖项)。不幸的是,当我尝试打开一个新的虚拟环境时(在bash中,在OSX中),我看到以下错误:

   $ virtualenv venv
Overwriting /Users/danwalsh/Desktop/naomi/venv/lib/python2.7/site.py with new content
New python executable in /Users/danwalsh/Desktop/naomi/venv/bin/python
copying /Users/danwalsh/anaconda/bin/python => /Users/danwalsh/Desktop/naomi/venv/bin/python
copying /Users/danwalsh/anaconda/bin/../lib/libpython2.7.dylib => /Users/danwalsh/Desktop/naomi/venv/lib/libpython2.7.dylib
Overwriting /Users/danwalsh/Desktop/naomi/venv/lib/python2.7/distutils/__init__.py with new content
Installing setuptools, pip, wheel...
  Complete output from command /Users/danwalsh/Desktop/naomi/venv/bin/python - setuptools pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/pkgutil.py", line 581, in get_data
    mod = sys.modules.get(package) or loader.load_module(package)
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/__init__.py", line 94, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in <module>
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/download.py", line 15, in <module>
ImportError: cannot import name requests

----------------------------------------

...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/Users/danwalsh/anaconda/bin/virtualenv", line 6, in <module>
    sys.exit(virtualenv.main())
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv.py", line 945, in create_environment
    download=download,
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv.py", line 901, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/Users/danwalsh/anaconda/lib/python2.7/site-packages/virtualenv.py", line 797, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/danwalsh/Desktop/naomi/venv/bin/python - setuptools pip wheel failed with error code 1

我已经搜索了错误,但是似乎没有一种解决方案适用于这种情况。从这里去哪里可能是个好地方?

1 个答案:

答案 0 :(得分:0)

为了后代,这是我克服此错误的方法:

正如Prashant Rana指出的那样,anaconda正在该系统上使用。解决方案是使用anaconda而不是venv创建虚拟环境。在外壳中,我运行了:

$ conda install -c conda-forge desired_module_name

然后

$ conda create -n mypython3 python=3

最后

$ source activate mypython3