简体   繁体   English

使用Python 3设置virtualenv时出错

[英]Error when setting up virtualenv with Python 3

I'm attempting to create a virtualenv (using virtualenvwrapper) with Python 3 as my default interpreter, but keep receiving the same error after un/reinstalling Python 3, virtualenv, and virtualenvwrapper several times. 我正在尝试使用Python 3作为我的默认解释器创建virtualenv(使用virtualenvwrapper),但是在多次重新安装Python 3,virtualenv和virtualenvwrapper之后仍然会收到相同的错误。

$ mkvirtualenv -p /usr/local/bin/python3 test-env
Running virtualenv with interpreter /usr/local/bin/python3
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 23, in <module>
    import subprocess
  File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 405, in <module>
    import _posixsubprocess
ImportError: dlopen(/Library/Python/2.7/site-packages/_posixsubprocess.so, 2): Symbol not found: _PyString_AsString
  Referenced from: /Library/Python/2.7/site-packages/_posixsubprocess.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/_posixsubprocess.so

I have both Python 2 (prepackaged version for OS X) and Python 3 (via brew install python3 ) installed. 我安装了Python 2(OS X的预打包版本)和Python 3(通过brew install python3 )。

I can create virtualenvs fine using any of my Python 2 binaries. 我可以使用我的任何Python 2二进制文件创建virtualenvs。

I had the exact same error, and in my case I was able to solve it with the following steps: 我有完全相同的错误,在我的情况下,我能够通过以下步骤解决它:

$ brew unlink python3
$ brew link --overwrite python3
$ unset PYTHONPATH

After that, virtualenv worked as expected. 在此之后, virtualenv按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM