[英]remove virtual environment created with venv in python3
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 virtualenv
or pyvenv
.这似乎是一个谷歌搜索应该很容易回答的问题,但我只找到了删除使用
virtualenv
或pyvenv
创建的环境的答案。
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 的所有其他内容的保存位置。
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.要停用,只需在虚拟环境树中的任何位置执行“停用”bash 命令。
In your venv project folder created using python3 -m venv .
在使用
python3 -m venv .
创建的 venv 项目文件夹中python3 -m venv .
or whatever, run this to remove the venv files:或者其他什么,运行它来删除 venv 文件:
rm -r bin include lib lib64 pyvenv.cfg share
If you're still in the venv by using source bin/activate
, run deactivate
first.如果您使用
source bin/activate
仍然在 venv 中,请先运行deactivate
。
However, according to this page , one should always use python3 -m venv venv
so the venv files are neatly contained in a single venv
folder in your project root.但是,根据此页面,应该始终使用
python3 -m venv venv
以便 venv 文件整齐地包含在项目根目录的单个venv
文件夹中。 That way the Visual Studio Code Python extension can find/use it as well.这样 Visual Studio Code Python 扩展也可以找到/使用它。
To delete a environment in WINDOWS.在 WINDOWS 中删除环境。 Make sure you are in activated environment:
确保您处于激活的环境中:
$ 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
There is no built-in way to remove a virtualenv created with python3 -m venv <name>
.没有内置方法可以删除使用
python3 -m venv <name>
创建的 virtualenv。 If you created a python3.6 virtualenv in, for instance, /usr/local
then you can remove it with an Ansible playbook like:例如,如果您在
/usr/local
中创建了一个 python3.6 virtualenv,那么您可以使用 Ansible 剧本将其删除,例如:
---
- name: Remove virtualenv
hosts: all
vars:
venv: /usr/local
virtualenv_files:
- pyvenv.cfg
- bin/activate
- bin/activate.csh
- bin/activate.fish
- bin/easy_install
- bin/easy_install-3.6
- bin/pip
- bin/pip3
- bin/pip3.6
- bin/python
- bin/python3
- bin/python3.6
- bin/wheel
- lib/python3.6/site-packages
tasks:
- name: Freeze virtualenv
shell: |
set -e
source "{{ venv }}/bin/activate"
pip3 freeze > /tmp/frozen
args:
creates: /tmp/frozen
register: frozen
failed_when: false
- name: Remove site-packages from virtualenv
when: frozen.rc == '0'
become: true
shell: |
set -e
source {{ venv }}/bin/activate
pip3 uninstall -y -r /tmp/frozen
- name: Remove virtualenv_files
become: true
file:
path: "{{ venv }}/{{ item }}"
state: absent
loop: "{{ virtualenv_files }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.