Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create virtual environment for python 3.7.0?

I'm able to install it with root user but I wanted to install it in a clean environment. My use case is to test the installation of another application with pip for the customer who is using python3.7.0

sudo apt-get update

sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev

sudo apt-get install python3-pip python3-dev

sudo apt-get install python3.7

Thanks.

like image 503
Pankaj Singh Avatar asked Oct 15 '18 11:10

Pankaj Singh


2 Answers

(assuming python3.7 is installed)

Install virtualenv package:

pip3.7 install virtualenv

Create new environment:

python3.7 -m virtualenv MyEnv

Activate environment:

source MyEnv/bin/activate
like image 99
Mikhail Stepanov Avatar answered Sep 21 '22 20:09

Mikhail Stepanov


Some added information, if you are trying for some version like python 3.7.10, which might give following error upon executing pip3.7.10 install virtualenv

.pyenv/versions/3.7.10/bin/python: No module named virtualenv

So, in a general sense you can do the following steps: [commands are specific to MacOs, I am currently using with the new M1 chip]

  1. After installing 3.7.10 using pyenv, make it global.
brew update
brew install pyenv

set environment variables

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

look at the pyenv list to see if the version you install is there or not and install and make it global

pyenv install --list
pyenv install 3.7.10
pyenv global 3.7.10
  1. create your virtual environment now with this version
python -m venv MyEnv 
  1. activate it
source MyEnv/bin/activate
like image 43
Ankita Avatar answered Sep 17 '22 20:09

Ankita