I've tried the normal way, sudo apt-get install python3.6
, but... well... that didn't work.
So, how would I go about it? (I'd preferably not build it on my own)
I'm using Ubuntu 16.04.
I've tried the normal way, sudo apt-get install python3.6
, but... well... that didn't work.
So, how would I go about it? (I'd preferably not build it on my own)
I'm using Ubuntu 16.04.
Deadsnakes removed support for 16.04. You can use this unofficial repo for now. https://github.com/deadsnakes/issues/issues/195
sudo add-apt-repository -y ppa:jblgf0/python
sudo apt-get update
sudo apt-get install python3.6
J. Fernyhough's PPA used to be an alternative option, but he has shut it down to protest against (ab)use.
You can install pip
like this:
curl https://bootstrap.pypa.io/pip/3.6/get-pip.py | sudo python3.6
If you are using Ubuntu 16.10 or 17.04, then Python 3.6 is in the universe repository, so you can just run:
sudo apt-get update
sudo apt-get install python3.6
To invoke the Python 3.6 interpreter, run python3.6
.
Ubuntu 17.10 and 18.04 already come with Python 3.6 as default. Just run python3
to invoke it.
dict
that shows up in some rare circumstances).
– Marius Gedminas
Dec 29 '16 at 14:40
ppa:jonathonf
version of python 3.6 doesn't include pip
or even ensurepip
so it's very difficult to install packages. How should I resolve this?
– Migwell
Feb 10 '17 at 06:14
sudo apt remove python3.5
or anything like it; Python is more fundamentally baked into Ubuntu than you would think, and you could break your Ubuntu install. If you want python3
to map to python3.6
, create a symlink instead!
– Huw Walters
Apr 28 '17 at 09:09
python3.6-pip
package, and so I used curl https://bootstrap.pypa.io/get-pip.py | sudo python3.6
to install pip
.
– Asclepius
Jun 20 '17 at 20:26
ppa:deadsnakes/ppa
instead of fkrull.
– Jason R. Coombs
Sep 10 '17 at 01:32
ppa:jonathonf/python-3.6
arrived with broken pip and no easy_install on 14.04. However, I've managed to fix it by installing easy_install and then reinstalling pip via curl https://bootstrap.pypa.io/ez_setup.py -o - | python3.6 && python3.6 -m easy_install pip
Just in case someone runs into the same problem...
– FirefoxMetzger
Dec 03 '17 at 17:36
python3
package in the first place? It is essential for proper OS operation.
– edwinksl
Jan 08 '18 at 19:11
pip
to install with ppa:jonathonf/python-3.6
. On the other hand, ppa:deadsnakes/ppa
worked flawlessly (apt-get install python3.6 python3.6-venv -y
).
– Michael Herrmann
Feb 26 '18 at 16:00
deadsnakes
PPA first.
– edwinksl
Feb 26 '18 at 17:44
deadsnakes
one also has a more recent Python version (3.6.4 instead of 3.6.3).
– Michael Herrmann
Feb 27 '18 at 08:06
pip3
is not broken after installing deadsnakes package and I don't know how to update it
– lurscher
Nov 26 '18 at 02:12
sudo apt install python3-pip
– Quitiweb
Sep 12 '19 at 09:41
I would recommend pyenv to solve your woes. It doesn't use Aptitude, and does involve "building it yourself", but it's fully automated. You can build and install a new (or old) version of Python by simply saying pyenv install 3.6.0
. Everything runs as your user, so you don't have to worry about messing up the Python used by Ubuntu itself.
Plus, the answer to the follow-up question "How do I install Python 3.7 using apt-get?" has the same answer: pyenv update; pyenv install 3.7.0
. It will generally work same day of a release because you don't need to wait for someone else to package it for Ubuntu. See all the versions you can install with pyenv install --list
Install tools and headers needed to build CPythons (exotic Pythons like PyPy or Jython may have other dependencies). Git is used by pyenv, plus it also enables builds/installs of source branches, so you could install whatever 3.8 is right now, i.e. the master branch of CPython fresh off GitHub:
sudo apt-get install -y git
sudo apt-get install -y build-essential libbz2-dev libssl-dev libreadline-dev \
libffi-dev libsqlite3-dev tk-dev
# optional scientific package headers (for Numpy, Matplotlib, SciPy, etc.)
sudo apt-get install -y libpng-dev libfreetype6-dev
Run the installer script (installs pyenv and some very useful pyenv plugins by the original author; see here for more)
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
Add init lines to your ~/.profile
or ~/.bashrc
(it mentions it at the end of the install script):
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Restart your shell (close & open or exec $SHELL
) or reload the profile script. (with e.g. source ~/.bashrc
)
Done!
To not touch the system Python (generally a bad idea; OS-level services might be relying on some specific library versions, etc.) make your own environment, it's easy! Even better, no sudo
, for it or pip
installs!
Install your preferred Python version (this will download the source and build it for your user, no input required)
pyenv install 3.6.0
Make it a virtualenv so you can make others later if you want
pyenv virtualenv 3.6.0 general
Make it globally active (for your user)
pyenv global general
Do what you want to with the Python/pip, etc. It's yours.
If you want to clean out your libraries later, you could delete the virtualenv (pyenv uninstall general
) or make a new one (pyenv virtualenv 3.6.0 other_proj
). You can also have environments active per-directory: pyenv local other_proj
will drop a .python-version
file into your current folder and any time you invoke Python or pip-installed Python utilities from it or under it, they will be shimmed by pyenv.
bash: pyenv: command not found
, fish: Unknown command 'pyenv'
$PATH
, there should be one entry that ends in something like .pyenv/bin
. If it's missing make sure you followed #3 AND #4 (restart your shell) under Install pyenv above.pyenv: no such command 'virtualenv'
pyenv commands
.rm -r ~/.cache/pip/wheels/
.)
– Marius Gedminas
Jan 11 '17 at 06:30
tk-dev
. In this way, pyenv will install python with the tkinter
module. This may be useful in case the python3-tk
module is not updated on the repository (in my case it was only for python 3.5).
– gc5
Jan 18 '17 at 11:00
:(
– Nick T
Jan 27 '17 at 17:54
pyenv
need to be installed for every user which need Python? And if I have 3 users who need same Python 3.6 version, then it'll have to compile it 3 times and it will take 3x disk space? If that's true then it sucks… :/
– Display Name
Jun 25 '17 at 11:54
/opt
or whatever and adding some symlinks to /bin
. I find it being user-only to be extremely useful; users don't need sudo (other than libs). Disk space is cheap.
– Nick T
Jun 25 '17 at 15:30
pyenv: Git is not installed, can't continue.
error when running the installer script
– virtualxtc
May 23 '18 at 18:27
#!/usr/bin/python
scripts to #!/usr/bin/env python
.
– Nick T
Sep 19 '18 at 21:29
It depends on which version of Ubuntu you are using.
Since Python 3.6 is installed in the universe repository of Ubuntu 16.10 and Ubuntu 17.04, you can directly install python 3.6 from the repository. Just use the commands below:
sudo apt update
sudo apt install python3.6
There are two ways to install Python3.6 on Ubuntu 16.04
Install the necessary dependencies, download the python 3.6 source code, and build the environment and install
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall
You can install Python 3.6 from PPA using the commands below
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.6
If Python 3.6 is correctly installed, you can invoke the python interpreter by running python3.6
in the terminal.
I hope this helps. If you are having any issues, you can check this blog post here.
sudo add-apt-repository ppa:deadsnakes/ppa && sudo apt install python3.6
worked for me on Ubuntu 20.04
–
Apr 24 '20 at 22:38
An alternative route if you can't find any working repos would be you could try compiling yourself from source. You can find the source code on the download page. Then download and untar the tarball; for example for Python-3.6.1.tgz
.
The process for untarring the tgz file is:
tar -xvzf /path/to/yourfile.tgz
Once you are in the file path the file was unzipped to, run:
./configure
make
make altinstall
And hopefully this should solve the problem for you.
(id preferably not build it on my own)
. Maybe it'd be better to go the apt
route if possible.
– TheWanderer
Dec 28 '16 at 20:11
"sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev"
– Joe
Apr 27 '18 at 15:43
Python
itself, otherwise using this Python
you won't be able to use pip
and possibly other issues will also occur. For me, installing packages in the aforementioned link was enough. But I needed to upgrade pip
later for my use case.
– hafiz031
Sep 02 '21 at 10:43
Your best bet is to upgrade to Ubuntu 20.04 and then install it from the deadsnakes
PPA:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.6
Otherwise, you can try to figure out how to install the deadsnakes
PPA on a version of Ubuntu that they don't support. They only support Long Term Support (LTS) versions of Ubuntu, which 19.04 and 19.10 are not (but Ubuntu 20.04 is). I could've sworn I saw a thread about people doing it somewhere on Github https://github.com/deadsnakes/issues/issues?q=is%3Aissue+is%3Aclosed but I can't find it now.
Also check out this answer about downloading a deb-package https://stackoverflow.com/a/55858634/3064538
But if you can't do any of those, then your last resort is compiling it from source, which you do by first installing a C compiler
sudo apt install gcc
then going to https://www.python.org/downloads/ and finding the latest micro version of 3.6 (3.6.10 as I'm writing this) and compiling it from source, like this
wget -P ~/Downloads https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tar.xz
cd ~/Downloads
tar -xJf Python-3.6.10.tar.xz
cd Python-3.6.10
and then
./configure
make
make test
sudo make altinstall
The last command uses altinstall
instead of install
so that 3.6 is installed as python3.6
and pip3.6
. If you change the last command to sudo make install
(without the alt
) then that will install it as python3
, which will overwrite the version of Python 3.7 (and pip) you have installed now.
Updating is left as an exercise for the reader.
which python3.6
and which pip3.6
return before running make altinstall
–
Dec 08 '20 at 13:32
For Ubuntu 15.10 I installed it successfully using this method:
sudo add-apt-repository ppa:jonathonf/python-3.6
But I edited this file:
sudo vi /etc/apt/sources.list.d/jonathonf-ubuntu-python-3_6-wily.list
And I changed wily to trusty and then:
sudo apt-get update
sudo apt-get install python3.6
Perhaps suggesting Conda isn't a bad idea. I think it's at least easier than using pyenv. But maybe it does depend on what you intend to do with Python after all, because I think with Conda you may end up with some extra packages.
EDIT: It's probably worth mentioning that after you install Conda's default version of Python, you can install the version you need, here 3.6, using conda
like
conda install python==3.6
First, follow some of the other answers to install Python 3.6 or 3.7. Then, if want to install PyPi packages such as OpenEXR through pip
you may get some errors. Some of them (e.g. for OpenEXR's PyPi package) might get resolved by installing Python development package for your newly-installed Python. This can be done using the followings:
sudo apt-get install python3.6-dev
or
sudo apt-get install python3.7-dev
aptitude
, runaptitude search python3
– ridgy Dec 28 '16 at 20:13