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.
Ubuntu 14.04 (Trusty) and 16.04 (Xenial)
Deadsnakes removed support for 16.04. You can use this unofficial repo for now. https://github.com/deadsnakes/issues/issues/195
J. Fernyhough's PPA used to be an alternative option, but he has shut it down to protest against (ab)use.
NOTE: seems this ppa repo upto python 3.8,
and closed the old python 3.6 repo, but still can't install pip.
Ubuntu 16.10 and 17.04
If you are using Ubuntu 16.10 or 17.04, then Python 3.6 is in the universe repository, so you can just run:
After installation for Ubuntu 14.04, 16.04, 16.10 and 17.04
To invoke the Python 3.6 interpreter, run
python3.6
.Ubuntu 17.10, 18.04 (Bionic) and onwards
Ubuntu 17.10 and 18.04 already come with Python 3.6 as default. Just run
python3
to invoke it.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 withpyenv install --list
Install pyenv
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:
Run the installer script (installs pyenv and some very useful pyenv plugins by the original author; see here for more)
Add init lines to your
~/.profile
or~/.bashrc
(it mentions it at the end of the install script):Restart your shell (close & open or
exec $SHELL
) or reload the profile script. (with e.g.source ~/.bashrc
)Done!
Setting up an environment
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 orpip
installs!Install your preferred Python version (this will download the source and build it for your user, no input required)
Make it a virtualenv so you can make others later if you want
Make it globally active (for your user)
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.Troubleshooting
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
.It depends on which version of Ubuntu you are using.
Ubuntu 16.10 and Ubuntu 17.04
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:
Ubuntu 16.04
There are two ways to install Python3.6 on Ubuntu 16.04
1. Compile and install python 3.6 on Ubuntu 16.04
Install the necessary dependencies, download the python 3.6 source code, and build the environment and install
2. Install python 3.6 on Ubuntu 16.04 from PPA
You can install Python 3.6 from PPA using the commands below
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.
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:
Once you are in the file path the file was unzipped to, run:
And hopefully this should solve the problem for you.
Your best bet is to upgrade to Ubuntu 20.04 and then install it from the
deadsnakes
PPA: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
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
and then
The last command uses
altinstall
instead ofinstall
so that 3.6 is installed aspython3.6
andpip3.6
. If you change the last command tosudo make install
(without thealt
) then that will install it aspython3
, which will overwrite the version of Python 3.7 (and pip) you have installed now.Updating is left as an exercise for the reader.
For Ubuntu 15.10 I installed it successfully using this method:
But I edited this file:
And I changed wily to trusty and then:
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
likeConsider pyenv + pipenv which is to replace using PIP + virtual environments using Pipfile
Then in Pipfile
https://stackoverflow.com/a/49800061/1689770
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