python virtual environment
The virtual environment venv module (Lib/venv/) supports creating "virtual environments", independent packages installed in a separate directory. A virtual environment is created on top of an existing Python installation (Virtual Environments base).
A Python virtual environment is very important. It prevents package version or Dependency conflicts between the projects
Suppose there are 2 projects: Project A and Project B. Project A needs version 1 package, and Project B needs version 2 package. If projects A and B are running without a virtual environment, there may be a possibility of conflict between the 2 versions of the project. It allows testing with different versions of projects
Python has a built-in venv module to install Python Packages
python -m venv firstProject
or
python3 -m venv firstProject
The first Project folder structure will look like this:
bin include lib lib64 pyvenv.cfg
To use the virtual environment created, you have to activate it. To activate the virtual environment created, type the following command,
source firstProject/bin/activate
If the virtual environment is activated, you will get a response like this,
(myfirstproject) izzu@izzumon:~/Documents/fastapi_interview/myfirstproject$
If Python virtual environment is activated, you can install the packages using PIP using the following command,
pip install
pip list
Use the below command to deactivate a Python virtual environment:
deactivate
When the Python virtual environment is deactivated, installed packages inside the environment cannot be used until activated. But you can reactivate it and use it.
To reactivate the Python virtual environment, use the same command that was used to activate the environment.
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Ask your coding-related doubts and get answers.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Add your technical blogs and read technical topics.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.