DEV Community

ruchikaatwal
ruchikaatwal

Posted on

Working with multiple python and pip version on one machine with virtual enviornment.

Based on python requirment you can first instal python version you want. Just time of virtual environment creation mention python version. Below have provided example with python3.7. if you want to use create python3.8 or any other version, replace python3.7 with your python version.

  • Create python virtual environment without pip
$ python3.7 -m venv myenv_python37 --without-pip
Enter fullscreen mode Exit fullscreen mode
  • Activate python virtual environment you created above
$ source myenv_python37/bin/activate
Enter fullscreen mode Exit fullscreen mode
  • Now, install pip inside virtual environment
$ curl https://bootstrap.pypa.io/get-pip.py | python
Enter fullscreen mode Exit fullscreen mode

If you get error while installing pip:

ModuleNotFoundError: No module named 'distutils.cmd'
Enter fullscreen mode Exit fullscreen mode

install below distutils package

$ sudo apt-get install python3.7-distutils
Enter fullscreen mode Exit fullscreen mode

Install all requirement for python 3.7 inside virtual enviornment

$ pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode
  • After your work is done, close virtual environment

Note:

  • This helps maintaining multiple python and pip version on one system and using python and its supported package based on your requirement.
  • All packages from requirements.txt would be accesible inside virtual environment only, not global on your system for python3.7

Top comments (0)