how to use venv
时间: 2023-08-07 22:07:53 浏览: 123
组网需求-python虚拟环境venv用法详解
To use venv (Virtual Environment) in Python, you can follow these steps:
1. Open your terminal or command prompt.
2. Navigate to the directory where you want to create the virtual environment.
3. Run the following command to create a new virtual environment:
```
python -m venv myenv
```
Replace "myenv" with the desired name for your virtual environment.
4. Activate the virtual environment by running the appropriate command based on your operating system:
- On Windows:
```
myenv\Scripts\activate
```
- On macOS/Linux:
```
source myenv/bin/activate
```
5. Once activated, you can install packages and run Python scripts within the virtual environment without affecting your global Python installation.
6. To deactivate the virtual environment, simply run the following command:
```
deactivate
```
Remember to replace "myenv" with the actual name you chose for your virtual environment. This allows you to isolate your project dependencies and avoid conflicts between different projects.
阅读全文