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 trialArturo Acosta
7,638 PointsMaybe it went over my head but i realized she's typing python3 when executing the code, why?
I've been using python file_name.py to execute and its been all fine but i don't know if there is a difference and don't remembered if it was previously mentioned.
4 Answers
Steven Parker
231,248 PointsIf you have a modern Python installation, it's version 3. People who have been developing a long time might also have a Python version 2 installation, and they get into the habit of typing the version number with the name to be sure to run the correct one.
The important point is that when you type "python" you're doing the same thing as when you see the instructor type "python3".
Saikat Chowdhury
3,128 PointsIf you type in Workspace REPL ,
- python and enter , you will get Python 3.6.4 (it is a version of python)
- if you run python3 and enter , it will return same as before (Python 3.6.4)
- If you want, you can try python2 and enter, it will show Python 2.7.12
Here, i want to say .. If different versions of python installed in your machine then by mention python or python3 or python2 command can help you to access proper version of python shell. For us in workspace, python and python3 is mapped to same version thats why when we run (python ../ python3 ..) it works seamlessly.
Moaz Mansour
4,594 PointsThanks, Arturo for the question. It is a matter of calling the right python. For instance, my Mac comes with a pre-installed python of version 2 so when I type down "python" in the shell it opens up the Python V2.X REPL. If I wanna access another version of python in this case version 3.x I install this new version and add the path to the executable file to the PATH variable in the shell and then call it by typing "python3". This means if I am testing or running my code in Python V2.x I should call "python" and if I am testing to running my code in Python version 3 I should call "python3". This also works for python packaging installation so if I am installing or updating a package or module for version 2 I would use "pip" and if I am doing the same for version 3 I would use "pip3"
Leonard Peris
15,784 PointsI'd just like to expand the previous answers. As Steven Parker, Moaz Mansour & Saikat Chowdhury have rightly pointed, python2
and python3
launch the Python2 and Python3 REPLs respectively.
Python2 is the first implementation of Python. Python3 is the next version that aims to address and fulfill shortcomings of the prior implementation of Python. Unfortunately, it is not backwards compatible with Python2.
I urge you to read up on the differences between Python2 and Python3