I'd like to start by pointing out that this question may seem like a duplicate, but it isn't. All the questions I saw here were regarding pip for Python 3 and I'm talking about Python 3.6. The steps used back then don't work for Python 3.6.
- I got a clear Ubuntu 16.10 image from the official docker store.
- Run
apt-get update
- Run
apt-get install python3.6
- Run
apt-get install python3-pip
- Run
pip3 install requests bs4
- Run
python3.6 script.py
Got ModuleNotFoundError
below:
Traceback (most recent call last):
File "script.py", line 6, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Python's and pip's I have in the machine:
python3
python3.5
python3.5m
python3.6
python3m
python3-config
python3.5-config
python3.5m-config
python3.6m
python3m-config
pip
pip3
pip3.5
This website contains a much cleaner solution, it leaves pip intact as-well and one can easily switch between 3.5 and 3.6 and then whenever 3.7 is released.
http://ubuntuhandbook.org/index.php/2017/07/install-python-3-6-1-in-ubuntu-16-04-lts/
A short summary:
Then
Then to select python 3.6 run
and select '2'. Then
To update pip select the desired version and
Tested on Ubuntu 16.04.
Let's suppose that you have a system running Ubuntu 16.04, 16.10, or 17.04, and you want Python 3.6 to be the default Python.
If you're using Ubuntu 16.04 LTS, you'll need to use a PPA:
Then, run the following (this works out-of-the-box on 16.10 and 17.04):
When you have completed all of the above, each of the following shell commands should indicate
Python 3.6.1
(or a more recent version of Python 3.6):In at least in ubuntu 16.10, the default
python3
ispython3.5
. As such, all of thepython3-X
packages will be installed for python3.5 and not for python3.6.You can verify this by checking the shebang of
pip3
:Fortunately, the pip installed by the
python3-pip
package is installed into the "shared"/usr/lib/python3/dist-packages
such that python3.6 can also take advantage of it.You can install packages for python3.6 by doing:
For example:
This answer assumes that you have
python3.6
installed. Forpython3.7
, just replace3.6
with3.7
.Installation
With regard to installing
pip
, usingcurl
(instead ofwget
) avoids writing the file to disk.If you wish to avoid using
sudo
, refer to the linked documentation for installing locally using the--user
flag.-H flag
The
-H
flag is evidently necessary withsudo
in order to prevent errors such as these when installing pip for an updated python interpreter:Verification
After this,
pip
,pip3
, andpip3.6
can all be expected to point to the same target:Of course you can alternatively use
python3.6 -m pip
as well.