[英]When I try to activate a virtual environment with venv I get an error
I am following this tutorial on how to set up a virtual environment in Python3.6 using the windows command prompt.我正在关注本教程,了解如何使用 windows 命令提示符在 Python3.6 中设置虚拟环境。 I had no problem generating the necessary file by running this:
通过运行以下命令生成必要的文件没有问题:
python3 -m venv venv-test
The tutorial then advises to activate the virtual environment by running this code:本教程然后建议通过运行以下代码来激活虚拟环境:
venv-test/Scripts/activate
But when I do this , I get the error...但是当我这样做时,我得到了错误......
File "venv-test/Scripts/activate", line 4
deactivate () {
^ SyntaxError: invalid syntax
I opened the generated 'activate' file and this seems to be the part that's causing the problem but I'm not sure how to correct it.我打开了生成的“激活”文件,这似乎是导致问题的部分,但我不确定如何纠正它。
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
Thanks in advance!提前致谢!
Try this:试试这个:
source venv-test/bin/activate
It worked here.它在这里工作。 Make sure you're in the folder that contains your venv, otherwise just mention its full path.
确保您位于包含您的 venv 的文件夹中,否则只需提及其完整路径。
I haven't got access to a windows machine at the moment but if I remember correctly you need to run activate.bat and I think you need the full path.我目前无法访问 Windows 机器,但如果我没记错的话,您需要运行 activate.bat 并且我认为您需要完整路径。
So something like:所以像:
C://code/project/venv-test/Scripts/activate.bat
not sure the reason why running不确定跑步的原因
venv-test/Scripts/activate
doesn't work but if you go into the directory venv-test/Scripts and THEN type activate it works fine.不起作用,但如果您进入目录 venv-test/Scripts 并输入 activate ,它可以正常工作。
在 Python 3.8 上,只需转到包含虚拟环境的文件夹并键入
source venv-test\scripts\activate
你必须运行 source venv-test/bin/activate 而不是 venv-test/Scripts/activate
I had the same problem before, try typing :我之前也遇到过同样的问题,试试输入:
venv-test/Scripts/activate.bat,
it worked for me它对我有用
change directory to scripts directory as follows:将目录更改为脚本目录,如下所示:
cd venv-test/Scripts
and run the activate file by typing并通过键入运行激活文件
activate
at the prompt在提示下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.