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.

Reference:

  1. https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-ubuntu-16-04
  2. http://stackoverflow.com/questions/12971443/is-python-package-virtualenv-necessary-when-i-use-python-3-3
  3. http://stackoverflow.com/questions/29934032/virtualenv-python-3-ubuntu-14-04-64-bit
  4. http://superuser.com/questions/1039369/how-to-create-a-python3-virtual-environment-as-of-2016
  5. https://docs.python.org/3/library/venv.html
  6. http://stackoverflow.com/questions/16123459/virtualenvwrapper-and-python-3

Leave a Reply

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