简体   繁体   English

使用 python 3 安装 virtualenv 时出错

[英]error with installing virtualenv with python 3

ive updated to python3 and downloaded virtualenv using: sudo /usr/bin/easy_install virtualenv我更新到 python3 并使用以下方式下载了 virtualenv: sudo /usr/bin/easy_install virtualenv

when i go to start the virtualenv i got the following error message: virtualenv project1 Traceback (most recent call last): File "/usr/local/bin/virtualenv", line 6, in <module> from pkg_resources import load_entry_point File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module> @_call_aside File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside f(*args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set working_set = WorkingSet._build_master() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master return cls._build_from_requirements(__requires__) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements dists = ws.resolve(reqs, Environment()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'zipp>=0.4' distribution was not found and is required by importlib-resources当我 go 启动 virtualenv 时,我收到以下错误消息: virtualenv project1 Traceback (most recent call last): File "/usr/local/bin/virtualenv", line 6, in <module> from pkg_resources import load_entry_point File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module> @_call_aside File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside f(*args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set working_set = WorkingSet._build_master() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master return cls._build_from_requirements(__requires__) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements dists = ws.resolve(reqs, Environment()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'zipp>=0.4' distribution was not found and is required by importlib-resources virtualenv project1 Traceback (most recent call last): File "/usr/local/bin/virtualenv", line 6, in <module> from pkg_resources import load_entry_point File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module> @_call_aside File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside f(*args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set working_set = WorkingSet._build_master() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master return cls._build_from_requirements(__requires__) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements dists = ws.resolve(reqs, Environment()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'zipp>=0.4' distribution was not found and is required by importlib-resources

i looked around and realised the that 'zipp' had not been installed so i installed that also.我环顾四周,意识到没有安装“zipp”,所以我也安装了它。 when i went to run the virtualenv again i got the same error message again as above.当我再次运行 virtualenv 时,我再次收到与上述相同的错误消息。 and for some reason it keeps referencing python 2.7 even though ive upgraded to python3.并且由于某种原因,即使我升级到 python3,它仍然引用 python 2.7。

please try this..请试试这个..

you just follow Exactly the bellow Items:您只需完全按照以下项目进行操作:

Open your Command Prompt AS ADMINISTRATOR -> right click on CMD and RUN AS ADMINISTRATOR以管理员身份打开命令提示符 -> 右键单击 CMD 并以管理员身份运行

go to which Folder to you want to create your VirtualENV: For example: > Cd C:\Users...\Documents\python\src go 要创建 VirtualENV 的文件夹: 例如: > Cd C:\Users...\Documents\python\src

type it: PIP install Virtualenv make sure your internet connection is Ok输入: PIP install Virtualenv确保您的互联网连接正常

4.type: python -m venv env 4.类型: python -m venv env

and then you can create your project inside this env folder..然后你可以在这个 env 文件夹中创建你的项目..

all Comment code should be write in Command Prompt AS Administrator所有注释代码都应在命令提示符 AS 管理员中编写

i ended up using the built in python 3 venv package.我最终使用了内置的 python 3 venv package。 it works just as well and it was straight forward and simple.它同样有效,而且简单明了。 thank you for all the help谢谢你的帮助

start the virtual environment: python3 -m venv project1 activate the virtual environment: source project1/bin/activate deactivate the virtual environment: deactivate启动虚拟环境: python3 -m venv project1激活虚拟环境: source project1/bin/activate停用虚拟环境: deactivate

If you're using Python 3.3 or later, you can use the built-in venv [ https://docs.python.org/3/library/venv.html] module.如果您使用的是 Python 3.3 或更高版本,则可以使用内置的 venv [ https://docs.python.org/3/library] This will reduce the number of dependencies, making installation and troubleshooting a bit easier.这将减少依赖项的数量,使安装和故障排除更容易一些。

To double-check that you are invoking the correct Python interpreter, run python3 -V or python -V (depending on how it's aliased).要仔细检查您是否调用了正确的 Python 解释器,请运行python3 -Vpython -V (取决于它的别名方式)。

Just try out.试试看。

virtualenv venv virtualenv venv

It should create a venv directory in same directory if python 3.x is being used.如果正在使用 python 3.x,它应该在同一目录中创建一个 venv 目录。

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

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