What is the difference between following commands:
python setup.py and
python3 setup.py - What if I only have python3.6 installed?
pythonandpython3would do the same thing? - Does it make difference only when I have different versions of python installed? If so, which version will be used with
python setup.py?
2 Answers
Yes, it will make difference if you have different versions of python installed.
This depends on the entries in on the PATH environment variable. Suppose you have two python installations, 2.7 and 3.8, now you have installed 2.7 before 3.8, and both were added to PATH, so when you type python, 2.7 interpreter launches. If you have done vice versa, then 3.8 would launch. You can type where python to determine location.
Also one thing is that there is a launcher named py, just type py -3.8 3.8 interpreter will launch and same on py -2.7
There is no single correct answer here, but we can offer some common observations.
- Some Linux distributions decided during the transition from Python 2 to Python 3 that
pythonshould always refer to Python 2, and the command to run Python 3 would bepython3with a 3 at the end. Now that Python 2 is becoming obsolete, this is being relaxed in some distros (i.e. now that they no longer ship Python 2 at all, thepythoncommand can be allowed to point to Python 3, too), but this is going to continue to exist in some form for some time. - Debian-based Linux distros have a mechanism called
update-alternativeswhich lets you define which version ofpythonexactly will be linked to the system-wide standard/usr/bin/python. There is similarly a set of alternatives for/usr/bin/python3. - If you have manually installed Python 3 somewhere, what works depends on where it was installed and whether that location is in your
PATH. A common arrangement is to have Python 3.14.159 somewhere like/opt/python-3.14.159/bin/python3.14.159and then rely on users who want to use this to create a symlink or alias to this binary so that they can simply call itpython(orpython3, or obviously also e.g.shirleyif they prefer that) - If you have an interactive alias, function, or personal shell script in your
PATHwith either of these names, obviously that overrides any system-wide setting, and could basically do anything at all, including but not limited to running a specific version of Python, ideally with all the command line arguments intact and correctly quoted (/path/to/system-wide/default/python "$@") but obviously with no guarantees of any sort. - On Windows, where many of these facilities don't exist, a common arrangement is for Python to be installed in
C:\python3.14.159\bin\Python.exe; you then have to haveC:\python3.14.159\binin yourPATHfor thepythoncommand to work. The installer lets you install the package anywhere, but if you just go with the defaults, this is what you commonly end up with. Because of the cumbersomeness of Windows, the standard install also includes a commandpywhich works around some of the rigidity of the platform to let you flexibly indicate which Python version exactly to run. There is usually not a separatepython3command, though users are of course free to create aCMDfile with that name to run Python (or play a video of Rick Astley performing his biggest hit if they so prefer).
To help us help you debug questions about your installation, you will commonly need to tell us exactly what you installed where and how, and show us the value of your PATH. If you have relevant functions, aliases, or personal shell scripts which shadow the system-wide default ones, show them too. On Unix-based platforms, the type and command commands can be used to show what will be executed (many guidances will tell you to use which or whereis, but don't; now we have to guess which non-standard command you are using, and where it is going to look). The Windows command whereis provides roughly the same functionality.
Don't call me Shirley, please.