Introduction
What is a virtual environment?
To avoid package conflicts between different projects, you can use virtual environments. This enables you to install dependencies for each project independently, without impacting the system-wide Python installation.
A virtual environment is a self-contained Python setup that includes its own package directories and a Python binary, either copied or linked from the original binary used to create the environment.
Where to store virtual environments?
When creating virtual environments, it is recommended to not have a virtual environment folder within the project. Reason being:
- It’s easier to back up your project without the bulky virtual environment folder.
- It’s easier to share your project with others without the virtual environment folder.
- Prevents you from accidentally adding the virtual environment folder to your version control system.
If you are keeping the virtual environment folder within the project, make sure to add it to the
.gitignore
file.
If you’re not using an interactive shell, you can use the environment by using the Python interpreter in the virtual environment. <path_to_env_folder>/bin/python <script.py>