gpt4 book ai didi

Python 3 虚拟环境问题

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:52 25 4
gpt4 key购买 nike

我遇到了类似于 this post 的问题,但我已经在运行最新版本的 virtualenv 并且我还得到了一个不同的 ImportError

使用 2.7 版(默认)的 virtualenv 工作正常,但我需要将 python3 用于另一个项目。我在 OSX 10.10.2 中使用 brew install python3 安装了它。

当我尝试时:

> pip install --upgrade virtualenv
Requirement already up-to-date: virtualenv in /Library/Python/2.7/site-packages
Cleaning up...

> virtualenv --version
12.0.7

> virtualenv -p python3 test

我仍然得到:

Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Failed to import the site module
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 73, in <module>
__boot()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 2, in __boot
import sys, imp, os, os.path
File "/Users/user/Desktop/project/studyprocessor/venv/bin/../lib/python3.4/imp.py", line 22, in <module>
from importlib import util
File "/Users/user/Desktop/project/studyprocessor/venv/bin/../lib/python3.4/importlib/util.py", line 12, in <module>
from contextlib import contextmanager
ImportError: No module named 'contextlib'
ERROR: The executable venv/bin/python3.4 is not functioning
ERROR: It thinks sys.prefix is '/Users/user/Desktop/project/studyprocessor' (should be '/Users/user/Desktop/project/studyprocessor/venv')
ERROR: virtualenv is not compatible with this system or executable

有什么想法吗?

最佳答案

您使用的pip程序对应的是Python 2.7版本。您需要使用 Python 3.x 对应的 pip。所以,你应该使用

pip3 install virtualenv

或者,您可以使用 venv module 在 Python 3.3+ 中创建虚拟环境, 像这样

python3 -m venv test

关于Python 3 虚拟环境问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28923926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com