Python Forum
Python version on Linux - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python version on Linux (/thread-25718.html)



Python version on Linux - whois1230 - Apr-09-2020

Hello, I'm running Linux Mint Cinnamon 18.3 64-bit and I want to learn Python 3. When I write
python --version
in the Terminal I get
user@user-Lenovo-ideapad-110-17IKB ~ $ python --version
Python 2.7.12
When I write
sudo apt-get install python3.5
in the Terminal I get
user@user-Lenovo-ideapad-110-17IKB ~ $ sudo apt-get install python3.5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.5 is already the newest version (3.5.2-2ubuntu0~16.04.9).
The following packages were automatically installed and are no longer required:
  codeblocks-common libcodeblocks0 libwxbase3.0-0v5 libwxgtk3.0-0v5
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 36 not upgraded.
How do I know which version I'm running?


RE: Python version on Linux - buran - Apr-09-2020

Linux mint18 has bot 2.7 and 3.5 versions.
python2 is the system version (i.e. the one linux rely on for its tools
If you want to use python3 use python3 command, or python3.5 not python.

Note that newest version is 3.8, so if you want to install - install 3.8/
in this case python will point to python2, python3 and python3.5 will point to 3.5 and python3.8 will point to newly installed 3.8
You can use pyenv to manage different installations.
also it's a good idea to work in virtual environments, so that system install is clean. You will need to install different 3-rd party packages and don't want to clutter the system versions.

Look at https://python-forum.io/Thread-Part-1-Linux-Python-3-environment
and also - https://python-forum.io/Thread-pyenv-Simple-Python-Version-Management
https://docs.python.org/3/library/venv.html


RE: Python version on Linux - whois1230 - Apr-10-2020

(Apr-09-2020, 01:22 PM)buran Wrote: Linux mint18 has bot 2.7 and 3.5 versions.
python2 is the system version (i.e. the one linux rely on for its tools
If you want to use python3 use python3 command, or python3.5 not python.

Note that newest version is 3.8, so if you want to install - install 3.8/
in this case python will point to python2, python3 and python3.5 will point to 3.5 and python3.8 will point to newly installed 3.8
You can use pyenv to manage different installations.
also it's a good idea to work in virtual environments, so that system install is clean. You will need to install different 3-rd party packages and don't want to clutter the system versions.

Look at https://python-forum.io/Thread-Part-1-Linux-Python-3-environment
and also - https://python-forum.io/Thread-pyenv-Simple-Python-Version-Management
https://docs.python.org/3/library/venv.html
user@user-Lenovo-ideapad-110-17IKB ~ $ sudo apt-get install python3.8
[sudo] password for user: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.8 is already the newest version (3.8.2-1+xenial1).
The following packages were automatically installed and are no longer required:
  codeblocks-common libcodeblocks0 libwxbase3.0-0v5 libwxgtk3.0-0v5
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 36 not upgraded.
user@user-Lenovo-ideapad-110-17IKB ~ $ python3 -V
Python 3.5.2
user@user-Lenovo-ideapad-110-17IKB ~ $ 
I installed python 3.8.2 and it's showing that I have 3.5.2?

bump Smile


RE: Python version on Linux - buran - Apr-10-2020

try with python3.8 if you want that version. python3 is alias for 3.5


RE: Python version on Linux - whois1230 - Apr-10-2020

(Apr-10-2020, 06:57 PM)buran Wrote: try with python3.8 if you want that version. python3 is alias for 3.5
user@user-Lenovo-ideapad-110-17IKB ~ $ python3.8 -V
Python 3.8.2
How do I know which version of python is IDLE using? Must I write
#!/usr/bin/python3
or
#!/usr/bin/python3.8
at the beginning of each new program?


RE: Python version on Linux - buran - Apr-10-2020

that line is called shebang. It is used only when you want to execute your script from command prompt without using python command in front of it. For that you need to make it executable.
In IDLE it doesn't matter.
you can see https://www.python.org/dev/peps/pep-0394/ for some recommendations what shebang to use.
also https://stackoverflow.com/q/6908143/4046632
For time being you can safely leave your scripts without one. I personally prefer to explicitly invoke the respective python and almost never use shebang