简体   繁体   English

设置python 3.7虚拟环境的问题

[英]Problems setting up a python 3.7 virtual environment

I am trying to create a new python 3.7 virtual environment on my local computer running Windows 8. I have python versions 3.6, 3.7, and 3.8 installed.我正在尝试在运行 Windows 8 的本地计算机上创建一个新的 python 3.7 虚拟环境。我安装了 python 版本 3.6、3.7 和 3.8。 Their exe's are named python36, python37, and python, respectively.它们的 exe 分别命名为 python36、python37 和 python。 All three are correctly added to PATH because I can enter each interpreter.所有三个都正确添加到 PATH 因为我可以输入每个解释器。

Within my new project's directory I tried to create a virtual environment with python37 -m venv env .在我的新项目目录中,我尝试使用python37 -m venv env创建一个虚拟环境。 It produced an error: Error: [WinError 2] The system cannot find the file specified , but it still created the directory.它产生了一个错误: Error: [WinError 2] The system cannot find the file specified ,但它仍然创建了目录。 However the Scripts subfolder is empty except for pythonw.exe .但是 Scripts 子文件夹是空的,除了pythonw.exe

In this question someone suggests doing python37 -m venv env --without-pip .这个问题中,有人建议做python37 -m venv env --without-pip When I tried this, the activation/deactivation scripts were created, but the virtual environment is using python 3.8.当我尝试此操作时,已创建激活/停用脚本,但虚拟环境使用的是 python 3.8。

It is my understanding that venv will create the virtual environment with what ever python exe you use to call it, so I don't understand how this can happen.我的理解是 venv 将使用您用来调用它的任何 python exe 创建虚拟环境,所以我不明白这是怎么发生的。 I've verified that python37 points to the correct place with where python37 , and can even enter the 3.7 interactive interpreter.我已经验证python37指向正确的位置where python37 ,甚至可以进入 3.7 交互式解释器。

The problem was that I renamed the python exe's.问题是我重命名了python exe。 I don't know exactly what goes wrong, but presumably at some point venv tries to find python.exe and is thrown off by the name.我不知道到底出了什么问题,但大概在某个时候venv试图找到python.exe并被名称抛弃。

Changing them back to python.exe and differentiating between the versions with their location fixed the problem.将它们改回python.exe并根据它们的位置区分版本解决了问题。

Edit: Check out Eryk's comments for more details.编辑:查看 Eryk 的评论以获取更多详细信息。

First create folder at any drive then go to that folder and install virtualenv package using pip.首先在任何驱动器上创建文件夹,然后转到该文件夹​​并使用 pip 安装virtualenv包。

pip install virtualenv

Then create your virtual environment.然后创建您的虚拟环境。

mkvirtualenv myvirtualenv

Then use below command to activate virtualenv in windows.然后使用下面的命令在 Windows 中激活 virtualenv。

myvirtualenv\Scripts\activate

After this you can install related package in current virtual environment.之后,您可以在当前虚拟环境中安装相关软件包。

The Python Standard Library for Creating Virtual Environment用于创建虚拟环境的 Python 标准库

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

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