Python - Create virtual environment
Pankaj Raundal
Technical Lead at Lionbridge | AWS | Azure | Python | Drupal developer
Why to create and manage separate?virtual environments?for your Python projects.?
Each environment can use different versions of package dependencies and Python. After you’ve learned to work with virtual environments, you’ll know how to help other programmers reproduce your development setup, and you’ll make sure that your projects never cause dependency conflicts for one another.
Let see in simple steps how to create the environment.
STEP 1:
Install venv "python3 -m pip install --user virtualenv
Note: Commands vary as per the python version for python2 command is "virtualenv" for python3 its "venv"
For sake of folders structure and keep code clean I have created folder "py/environment", where I will keep all my code. This can be done as per your need.
STEP 2:
Command to create environment
python3 -m venv ~/Pankaj/code/py/environments/venvim
STEP 3:
Command to activate the environemnt
source ~/Pankaj/code/py/environments/venvim/bin/activate
STEP 4:
To install package locally on your current environment run
pip install --editable.
STEP 5:
Now clone your projec files on your local
STEP 6:
Use below command to install all required packages
pip install -r <your_requirement_file>.txt -r <your_dev_only_requirement_file>.txt
STEP 7:
Run below command to create package and execute python code
python setup.py build
python setup.py install