本文介绍了为 Windows 激活 venv (Python 3.7.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在我的新项目中激活 venv(也是 Python 新手),

I can't activate the venv on my new project (new to Python too),

如果我做 python --version: Python 3.7.2

If I do python --version: Python 3.7.2

我在编辑器(与代码)中使用$ python -m venv ./venv"创建了 venv.

I created the venv using ' $ python -m venv ./venv ' in my editor (vs code).

现在激活是我有问题的地方,

and now to activate is where I have a problem,

尝试 1:

$ ./venv/Scripts/activate.bat

error : 'C:\Users\name' is not recognized as an internal or external command, operable program or batch file.
The system cannot find the path specified.

我的用户名由 2 个名称name & name"组成,中间有空格!那是问题吗?它只显示名字而不显示第二个.

My user name is formatted from 2 names "name & name" with space between them! Is that a problem? It just show first name and not the second.

尝试 2:

$ C:\Users/name & name/Desktop/ProjectFolder/venv/Scripts/activate.bat

error: 
[1] 15160
bash: C:Users/name: No such file or directory
bash: name/Desktop/ProjectFolder/venv/Scripts/activate.bat: No such file or directory
[1]+  Exit 127                C:\Users/name

推荐答案

尝试使用终端导航到包含使用更改目录 (cd) 命令的虚拟环境的文件夹.到达那里后,尝试输入:

Try using the terminal to navigate to the folder that contains your virtual environment using the change directory (cd) command. Once there, try typing:

source ./venv/Scripts/activate

另外,尝试打开 venv 文件夹并确保您的激活文件位于Scripts"文件夹而不是bin"文件夹中.当我创建一个虚拟环境时,我使用:

Also, try opening the venv folder and make sure your activate file is in the 'Scripts' folder and not the 'bin' folder. When I create a virtual environment, I use:

source ./venv/bin/activate

这篇关于为 Windows 激活 venv (Python 3.7.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:20