8

So I updated python using these instructions:

sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-devlibsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

then

cd ~/Downloads 
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
tar -xvf Python-3.5.0.tgz
cd Python-3.5.0

then

./configure
sudo make install



python3.5
Python 3.5.0 (default, Oct  3 2015, 03:16:42) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

and it worked but when I closed terminal, and wrote python -v it is still python 2.7 and still getting errors executing code that use v3+ standard libraries

How to make it working as 3.5?

5
  • This page may help you: stackoverflow.com/questions/19256127/… Commented Jan 24, 2017 at 21:34
  • 1
    add aliasalias python='/usr/bin/python3' to ~/.bashrc Commented Jan 24, 2017 at 21:35
  • Why didn't you just sudo apt-get install python3.5?
    – mkrieger1
    Commented Jan 24, 2017 at 21:38
  • @mkrieger1 tried it, when I close terminal and type python -v it is again 2.7
    – so1989
    Commented Jan 24, 2017 at 21:40
  • 2
    Python 3 is installed as the command python3.
    – mkrieger1
    Commented Jan 24, 2017 at 21:42

5 Answers 5

30

//install python 3.6

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt update
sudo apt install python3.6

//change default python

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

//view default

 python -V
1
  • Python 3.6 no longer available via ppa:jonathonf/python-3.6 .... Use "sudo add-apt-repository ppa:deadsnakes/ppa"
    – Vitalicus
    Commented Apr 27, 2023 at 10:26
6

You still have Python 2 installed, and the python command is still set up to invoke that version by default. Try running your scripts like this:

python3 yourscriptname.py

In /usr/bin/, "python" is actually a symlink to python2.7. If you'd rather not have to type the 3 at the end whenever you use python, change that symlink to point to python3 instead. Then python will run Python 3.5 and you can use python2.7 or just python2 to run Python 2.7 scripts.

EDIT: Alternatively, you could put alias python=python3 in your ~/.bashrc file to do the same thing, but without needing root access and for your user account only.

2
  • 1
    just write in terminal alias python=python3 from askubuntu.com/questions/320996/…
    – Budi Mulyo
    Commented Nov 30, 2018 at 13:46
  • 1
    @BudiMulyo If you add an alias via the terminal like that, it'll only last until you log out. It's probably better to add your alias to something like ~/.bashrc so that it'll be persistent. Nevertheless, it's a good idea - I'll add it to the answer. Commented Jun 9, 2020 at 5:44
2

You might just have destroyed your system python installation by doing

sudo make install

This installs in the default path! And will possibly overwrite anything your linux distro has there to work correctly. Never do sudo make installs if you're not sure where the resulting stuff goes. In case of Python, you should have done

sudo make altinstall

to have it installed next to the default python but the best thing is to install and use the python version via your distro's package manager.

1

I read that changing global python to 3.5 can cause some problems so I set build commands in geany for python3 and I can still run scripts outside by typing python3 xxx.py and it's comfortable now

0

Python no longer available via ppa:jonathonf/python-3.6 Use "sudo add-apt-repository ppa:deadsnakes/ppa"

install python 3.11.3

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11

change default python (with -f flag, forced)

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.11 /usr/bin/python -f

view default

 python -V

also can update pip packages

pip freeze > packages.txt
python3.11 -m pip install -r packages.txt

Not the answer you're looking for? Browse other questions tagged or ask your own question.