Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

python - 在virtualenv中使用Python 3(Using Python 3 in virtualenv)

Using virtualenv , I run my projects with the default version of Python (2.7).

(使用virtualenv ,我使用默认版本的Python(2.7)运行项目。)

On one project, I need to use Python 3.4.

(在一个项目中,我需要使用Python 3.4。)

I used brew install python3 to install it on my Mac.

(我使用brew install python3将其安装在Mac上。)

Now, how do I create a virtualenv that uses the new version?

(现在,如何创建使用新版本的virtualenv?)

eg sudo virtualenv envPython3

(例如sudo virtualenv envPython3)

If I try:

(如果我尝试:)

virtualenv -p python3 test

I get:

(我得到:)

Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.4.0_1/Frameworks/Python.framework/Versions/3.4'
New python executable in test/bin/python3.4
Also creating executable in test/bin/python
Failed to import the site module
Traceback (most recent call last):
  File "/Users/user/Documents/workspace/test/test/bin/../lib/python3.4/site.py", line 67, in <module>
    import os
  File "/Users/user/Documents/workspace/test/test/bin/../lib/python3.4/os.py", line 634, in <module>
    from _collections_abc import MutableMapping
ImportError: No module named '_collections_abc'
ERROR: The executable test/bin/python3.4 is not functioning
ERROR: It thinks sys.prefix is '/Users/user/Documents/workspace/test' (should be '/Users/user/Documents/workspace/test/test')
ERROR: virtualenv is not compatible with this system or executable
  ask by Prometheus translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

simply run

(只需运行)

virtualenv -p python3 envname

Update after OP's edit:

(OP编辑后更新:)

There was a bug in the OP's version of virtualenv, as described here .

(有没有在OP的版本virtualenv中的一个bug,如所描述这里 。)

The problem was fixed by running:

(该问题已通过运行解决:)

pip install --upgrade virtualenv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...