Creating venv inPython:
1 min readApr 17, 2023
Here are the commands to create a Python virtual environment:
- Open your terminal or command prompt.
- Navigate to the directory where you want to create your virtual environment.
- Run the following command to create a new virtual environment:
For Windows:
python -m venv myenv
For Mac and Linux:
python3 -m venv myenv
Here, myenv
is the name of your virtual environment. You can choose any name you like.
- Activate the virtual environment by running the following command:
For Windows:
myenv\Scripts\activate.bat
For Mac and Linux:
source myenv/bin/activate
You should see the name of your virtual environment appear in parentheses in your terminal prompt. This indicates that the virtual environment is active.
- Install any packages you need within the virtual environment using pip. For example:
pip install requests
This will install the requests
package within your virtual environment.
- When you’re finished working in the virtual environment, you can deactivate it by running the following command:
deactivate
This will return your terminal prompt to its normal state and deactivate the virtual environment.