Venv in Python

venv in python

I had a Python project that contained an installation file like “install.sh” that installed the project’s requirements on the operating system. Also, I had a small Python project on my laptop that also had its own requirements.

I’m not very professional at Python and I’m learning this lovely language. That’s why I didn’t pay attention to venv or virtual environments in Python. unfortunately, I ran the installation file to install the project and start working.

After one working day, when I returned to the previous projects, unfortunately, I saw that the project was not working properly and after a while, I realized that the requirements and dependencies of the project were not installed correctly and I noticed the problem.

Creating a Python virtual machine gives us the ability to install the requirements of each Python project independently and away from any conflicts with other Python projects.

The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. A virtual environment is created on top of an existing Python installation, known as the virtual environment’s “base” Python, and may optionally be isolated from the packages in the base environment, so only those explicitly installed in the virtual environment are available.

https://docs.python.org/3/library/venv.html?highlight=venv

Creating a Virtual Environment and Activating the Virtual Environment:

python3 -m venv my_env
source my_env/bin/activate
https://ioflood.com/blog/python-activate-venv/

Leave a Reply

Your email address will not be published. Required fields are marked *