How to run and manage different versions of Python with virtual environment support by using pyenv

In this post,I am sharing how we can run different versions of python easily with virtual environment support  by usng pyenv .I am using pyenv these days.I find it better than using virtualenv .My currently activated environment remains activated even after restarting Terminal shell which I prefer.Another feature of pyenv  is that you can set environment local to any folder.

Thanks : Yamashita  (Author of pyenv )

Steps :

1.Use pyenv-installer   to install pyenv.You can install pyenv by using this command on Terminal :

$ curl -L | bash


2.To update  pyenv ,use this command :

$ pyenv update

Screenshot from 2017-07-29 11-25-48.png


3.Open your .bashrc  file and make sure that these lines are added to it .Otherwise,you need to add these lines  to your .bashrc  file  by editing the file wih sudo command:

# Load pyenv automatically by adding
# the following to ~/.bash_profile:

export PATH=”/home/gaurav/.pyenv/bin:$PATH”
eval “$(pyenv init -)”
eval “$(pyenv virtualenv-init -)”


4. To install specific version of Python ,say Python 3.6.1 ,use this command :

$ pyenv install 3.6.1


5.To create a virtual environment system ,say  test which uses Python  3.6.1 which we installed in previous step,you can use this command :

$ pyenv virtualenv 3.6.1 test


6.To activate this new virtual environment test ,you need to use this command :

$ pyenv virtualenv 3.6.1 test


7.To list all virtual environments of pyenv ,use this command :

$ pyenv versions


7.To switch back to system Python ,use this command :

$ pyenv global system


Screenshot from 2017-07-29 11-29-28.png


8.To uninstall any virtual environment ,say test ,use this command and Entere when it asks for confirmation :

$ pyenv uninstall test


Now,you can easily run different versions of Python along with virtual environment support.

Thanks  for reading my post.I hope this post will be useful for them who  want to manage different versions of python with virtual environment support .If you have any query/question,please post in comments section.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s