Table of Contents
- Gives the path of the python installation
- Displays a summary of pip commands
- Displays details for the command
- Displays list of all python packages installed
- Step 01: Change directory to project folder
- Step 02: Create virtual environment
- Step 03: Activate it
- Step 04: Install required packages
- Step 05: Save installed packages or deactivate it
Using cmd commands, go to the project folder, where you need to create virtual environment and then write the following
python -m venv env-name
python -m venv env-name --system-site-packages
--system-site-packages gives access to the system site-packages directory [all system packages]
Then, you need to activate the newly created virtual environment env-name by
env-name\Scripts\activate.bat
Update the pip in the virtual environment:
python -m pip install --upgrade pip
Now, if you install packages using pip, all the packages will be installed only in the virtual environment env-name.
To deactivate the current virtual environment, just write the following
deactivate
pip freeze prints the list of all python packages installed with their version
You can manually copy the output and make a requirements.txt file. So that you can recreate the same environment on a different location or another device.
You can automate the task by the following command
pip freeze > requirements.txt
To recreate the same environment, at first create a new virtual environment, activate it and run the following
pip install -r requirements.txt
Run venv with a specific python version. You can run using the full path where python is installed.
"C:\Program Files\Python38\python.exe" -m venv venv38
We can create a virtual environment similar way explained above using cmd.
To select a specific python interpreter,
- We need to click Ctrl + P and then type > or Ctrl + Shift+ P
- Click Python: Select Interpreter
- Select an interpreter displayed or click + Enter interpreter path... and nagivate to the python.exe file of a specific virtual environment
Python Tutorial: VENV (Windows) - How to Use Virtual Environments with the Built-In venv Module