Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Can I install both Python 2 and Python 3 to Windows at the same time?

I'm following the "Setting up a Local Python Environment" course. It seems pretty straight forward to install a single version of Python. However, what if I want both version 2 and 3? How do I tell the command line which version to call to run my script? Do I make the same choice path choice for both versions at install time?

2 Answers

On a Mac, I am guessing you can do this in homebrew.

Some quick googling led me to this answer on Stack Overflow that might help you!

http://stackoverflow.com/questions/15912063/how-do-i-run-python-2-and-3-in-windows-7/17245543#17245543

This seems promising but I'm still not clear on the details. As I read it Python 3 now includes a launcher which can route a script back to Python 2 if desired. I'm not certain if you have to install 2 or 3 first. I'm also not certain if we should keep the default "add Python.exe to path" for either 2 or 3 or both or neither. I also can't figure out how pip is supposed to know if you want v2 or v3 of a package. Maybe I'll just stick with having a single version.

I decided to go ahead and try it. Seems to be working OK so far. If anyone else is interested in trying this all I did was get the python-2.7.9.msi and python-3.4.2.msi files and then install first version 2 and then version 3. I kept all default settings on both except for opting to install to local hard drive instead of modifying the PATH.

"py" brings up Python 2.7.9 and "py -3" brings up Python 3.4.2. Starting off a script with "#!python2" or "#!python3" will automatically pull in the correct interpreter when launched with "py <script_name>". I haven't tried out pip yet but otherwise it seems to be all good.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Probably? I'm not actually sure.

What I use on my Mac, that should work in Windows, is pyenv. I have 3 or 4 versions installed and active at all times but that's because I end up testing packages I've released against multiple versions.

Comments in the pyenv forum lead me to believe that it isn't supported on Windows and the developer has no interest in making that happen either.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

That's what I get for not checking first.