Python is a open source software. It has thousands of third-party packages developed by developers all over the world. All these packages were maintained by PiPy.
For developing complex application we need to install many third-party libraries based on the requirement. All these packages were installed in system level.
If we are working on two projects in parallel one project is dependent on python2.7 and other is dependent on python3.5.
After completion of development the installed packages are no more required.
And they may slowdown the working speed of the system. To avoid such conditions we use python virtual environment.
We use system package "python-pip" for virtualenv.
"virtualenv" is a third-party python package, it provides python virtual environment.
For developing complex application we need to install many third-party libraries based on the requirement. All these packages were installed in system level.
If we are working on two projects in parallel one project is dependent on python2.7 and other is dependent on python3.5.
After completion of development the installed packages are no more required.
And they may slowdown the working speed of the system. To avoid such conditions we use python virtual environment.
We use system package "python-pip" for virtualenv.
sudo apt-get install python-pip
"virtualenv" is a third-party python package, it provides python virtual environment.
Setup virtualenv python
activate env to use virtualenv
Install required packages
Un-Install packages from env
Get list of all installed packages
Save list of required packages with version
Install saved requirements
Deactivate the virtualenv when you finish work
pip install virtualenv virtualenv project_env # for python3 virtualenv -p python3 project_env
source project_env/bin/activate
pip install requests
pip remove requests
pip freeze
pip freeze > requirements.txt
pip install -r requirements.txt
deactivate
Advantages using python virtual environment
- We can experiment with new packages
- We can have list of required packages for future reference.
- We can maintain clean technical requirements for project.
Architecture
Virtual environment architecture |