If I open Terminal and type in python, I see the version is 2.7.4. How do I get python 3.4? And do I need IDLE if I have sublime text?
-
1This is a duplicate of askubuntu.com/questions/350751/…– don.joeyApr 18, 2014 at 9:31
-
6@don.joey: No, it's not a duplicate as 14.04 already has python 3.4 installed by default.– Florian DieschApr 18, 2014 at 12:11
-
@FlorianDiesch I thought 13.04 also came with python 3 installed by default.– don.joeyApr 18, 2014 at 12:33
-
What is the use of having a old version of python.. Is there a way to uninstall the old one and make the new as default.– A Umar MuktharApr 27, 2015 at 17:56
9 Answers
python 3.4 is installed on the stable release of Ubuntu 14.04. You need to use python3
to use python 3.4. For example, to execute a script file.py
, use:
python3 file.py
This will use python 3.4 to interpret your program or you can use the shebang to make it executable. The first line of your program should be:
#!/usr/bin/env python3
and then use chmod +x file.py
to assign executable permissions and then run your python script as ./file.py
which would use python3 to execute.
If you want python3 to be used when you type python on the terminal, you can use an alias. To add a new alias, open your ~/.bash_aliases
file using gedit ~/.bash_aliases
and type the following:
alias python=python3
and then save and exit and type
source ~/.bash_aliases
and then you can type
python file.py
to use python3 as your default python interpreter.
No, you don't need IDLE just to use python3 to interpret your programs.
-
Thanks. Is there a way to avoid typing "~/Dropbox/XXX/Pythonfiles/examplefile.py" when I want to interpret a Pythonfile (for instance "examplefile.py"? Apr 18, 2014 at 9:39
-
-
1) You can just go that directory(
~/Dropbox/XXX/Pythonfiles/
) first and then typepython examplefile.py
(this might be pretty dumb and not what you expected). 2) You could aliaspython ~/Dropbox/XXX/Pythonfiles/examplefile.py
as a whole to a command which would execute when you type in the custom aliased command. 3) You won't find if you didn' have any aliases before, that is absolutely fine, you can create one.– jobinApr 18, 2014 at 10:01 -
What's the command to create this .bash_aliases file in terminal? Apr 18, 2014 at 10:04
-
Thanks this worked. Is chmod +x file.py for all files or do you mean the individual pythonfile? Apr 18, 2014 at 11:19
Python 3 is installed by default on modern versions of Ubuntu, so you should already have it installed:
python3 -V
To install idle 3:
sudo apt-get install idle-python3.4
I had the same issue with my ubuntu desktop. My python book told me to call python by just typing python in the terminal but it was only calling the previous python version 2.
- First check if you have python version 3 or not. Open command terminal, type
python3
Do you see the acknowledgment that you do? done.
- If you don't; install using following command line.
sudo apt-get install python3
Hope this helps!
On Ubuntu 14.04 Python 3.4 is installed by default.
As recommended by PEP-394 you can use python
and python2
to run Python v2 (2.7) and python3
to run Python v3 (3.4).
-
how to make python 3.4 default for Netbeans IDE ? now it is 2.7.6 when I click auto detect it will not 3.4.1 not detecting in python platform manager(Netbeans IDE 8.0.1)– A JSep 19, 2014 at 11:59
In the terminal type: python3
The terminal will itself say to type:
sudo apt-get install python3-minimal
Do it and this will install Python 3.2.3.
Then in the terminal type: python3.4
-- you shall enter Python 3.4.1.
-
2
If needed for only one script, you can use an alias locally and temporarily.
When installing Letsencrypt, I got the following warning :
$ ./letsencrypt-auto --help
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
The cause: Python 2.7.9 was needed, while 2.7.5 was installed. Python 3 works as well. I opened the script and inserted the following alias after the shebang:
alias python=python3
Then the script worked. When it all finished this alias was removed. It only worked in this script. So starting python
from the terminal still got me version 2.7.5.
Ubuntu 18.04 LTS and above
Since Ubuntu 18.04 and beyond, you don't have to install Python 3, as it comes by default.
For Ubuntu 18.04 LTS and Debian Buster, we want to transition to Python 3.6 as the default (and probably only) Python 3 version.
References:
Otherwise install by the following command:
sudo apt-get install python3
Then to locate multiple Python installations, run one of these commands:
whereis python
which -a python python2 python3
locate python
or just type python
command and hit Tab twice.
To list installed Python packages, run: dpkg -l | grep -w python
.
To install a specific version, see: How to install specific Ubuntu packages, with exact version?
-
Good, this gives me python 3.6. Also there's python3.7 in repos available; however, I need to test a package against 3.4 specifically. Any hassle-free options?– ulidtkoAug 9, 2019 at 16:17
-
@ulidtko See: How to install specific Ubuntu packages, with exact version?– kenorbAug 12, 2019 at 9:38
Python3.4 is already installed on your system, you just need to call it with python3
instead of python
There are a ton of legacy python apps out there and thus the need for python 2.x , however as others mentioned python3 -V shows Python 3.4.0 is installed and thus with Ubuntu 14.x it is there.
python -V shows 2.7.6
python3 -V shows 3.4.0
Knowing which interpreter to use then is up to you.