Saturday, April 30, 2016

Using Python3

Do you need to start a virtual environment with python 3 instead of python 2.x? I'll show you how.

I am not going to show you how to change the python version of an existing virtual environment today, so if you have already started a virtual environment in python 2.x, please delete it and create a new one from scratch using the directions below.

First, let's make sure we have python3 installed. Check where your python3 is located:
which python3

A path should come up. However, if your system can't find it, that means you don't have it installed. Use Homebrew (brew install python3) and you should be good to go.

Now that we know where our python3 is installed, let's create a virtual environment that uses python3.

mkvirtualenv mycoolenv -p /usr/local/bin/python3

As you can see above, my python3 was located at /usr/local/bin/python3, but substitute yours with your particular path.

And there you have it! You have now created a virtual environment called mycoolenv that will use python3.



No comments:

Post a Comment