删除在python3中使用venv创建的虚拟环境

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44158676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:46:10  来源:igfitidea点击:

remove virtual environment created with venv in python3

pythonpython-3.xpython-venv

提问by McLawrence

How can I delete a virtual environement created with

如何删除创建的虚拟环境

python3 -m venv <name>

Can I just remove the directory?

我可以删除目录吗?

This seems like a question googling should easily answer, but I only found answers for deleting environments created with virtualenvor pyvenv.

这似乎是一个谷歌搜索应该很容易回答的问题,但我只找到了删除使用virtualenv或创建的环境的答案pyvenv

回答by gonczor

Yes, delete the directory. it's where executables for the venv and modules and libraries and entire other stuff for venvs is kept.

是的,删除目录。它是 venv 和模块和库的可执行文件以及 venvs 的所有其他内容的保存位置。

回答by Tushar Vazirani

You should deactivate your environment first. Not sure if not deactivating will cause any problem, but that's the right way to do it. Once you deactivate, you can simply delete the virtual environment directory.

您应该先停用您的环境。不确定不停用是否会导致任何问题,但这是正确的做法。停用后,您只需删除虚拟环境目录即可。

To deactivate, simple execute the 'deactivate' bash command anywhere inside your virtual environment tree.

要停用,只需在虚拟环境树中的任何位置执行 'deactivate' bash 命令。

回答by Dhrumil Panchal

To delete a environment in WINDOWS. Make sure you are in activated environment:

在 WINDOWS 中删除环境。确保您处于激活的环境中:

$ deactivate

This will deactivate your current environment. Now you can go to the directory where your folder or folder is present. Delete it manually. DONE!

这将停用您当前的环境。现在您可以转到您的文件夹或文件夹所在的目录。手动删除。完毕!

To create a new environment , Simply from bash:

要创建一个新环境,只需从 bash:

$ python3 -m venv venv

To activate it:

要激活它:

$ source venv/bin/activate

回答by Cees Timmerman

In your venv project folder created using python3 -m venv .or whatever, run this to remove the venv files:

在使用python3 -m venv .或其他方式创建的 venv 项目文件夹中,运行此命令以删除 venv 文件:

rm -r bin include lib lib64 pyvenv.cfg share

If you're still in the venv by using source bin/activate, run deactivatefirst.

如果您仍在使用 venv source bin/activatedeactivate请先运行。

However, according to this page, one should always use python3 -m venv venvso the venv files are neatly contained in a single venvfolder in your project root. That way the Visual Studio Code Python extension can find/use it as well.

但是,根据此页面,应该始终使用python3 -m venv venvvenv 文件,以便将 venv 文件整齐地包含在venv项目根目录的单个文件夹中。这样 Visual Studio Code Python 扩展也可以找到/使用它。