Python2 & Python3 in Virtual Environment

I started python2 in 2015 (It’s late… I know, why not Python3 to begin with? I don’t know…) and I set up my coding environment following this instruction (Coming soon). Over some conversations, I have decided to build my next repo with Python3 (Not sure what it will be yet). One of the first thing I learned about Python was Virtual Environment, undoubtedly it was also one of the first thing I looked into after deciding to switch into Python3.

The OS I used when I started python was OSX on a work computer. However, now that I am broke and jobless like many Trump voters, I set up Lubuntu on one of my old computers. The following discussion will be based on Linux environment.

My version of Lubuntu is based on Ubuntu 16.10, so by default it has both Python2 and Python3 pre-installed. [1] You may always check with the following command,

dpkg -l

or just type python3 and see what happens.

Now comes the hard part, decision making time! You will see from a simple google or discussions in [2-4] that you have a choice with venv or virtualenv. After some thoughts, I’ve decided to stay with virtualenv for now since you can easily using python3 in existing virtualenv without installing anything else. However, I believe venv will be the way to go in the long term as venv is now part of the standard libraries in Py3, and Py2 will go obsolete.

To set up Python3 with virtualenv, just use the following command: [6]

mkvirtualenv --python=/usr/bin/python3 env_name

where /usr/bin/python3 is the your python3 location, you may also use which python to find it.



Leave a Reply

Your email address will not be published. Required fields are marked *