I'm trying to install Python 3.6 or above with pip in an docker container that runs Ubuntu. I've tried quite a few things with no success
FROM ubuntu:18.04
RUN apt update
RUN apt install software-properties-common -y
RUN add-apt-repository ppa:deadsnakes/ppa
RUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN apt install python3.8 -y
RUN apt install pip
RUN pip install auto-sklearn
RUN pip install pandas
ADD test.py /
CMD [ "python", "./test.py" ]
This returns "Unable to locate package pip." I tried removing "apt install pip" incase Python 3.8 comes with it, but it gives me the error: "pip: not found."
FROM ubuntu:18.04
RUN apt install software-properties-common -y
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get update
RUN install python3-pip
RUN pip install auto-sklearn
RUN pip install pandas
ADD test.py /
CMD [ "python", "./test.py" ]
This installs pip, but auto-sklearn requires Python version 3.6 or higher and this installs a lower version. Auto-sklearn requires Linux as well which is why I'm using "FROM ubuntu" rather than "FROM python" cause "FROM python" seems to build a container on whatever native OS is running on the computer building the container, which for me is Windows.
I see two consecutive issues here, so let's address them accordingly:
Issue 1: missing pip in the Ubuntu image
This returns "Unable to locate package pip." I tried removing "apt install pip" incase Python 3.8 comes with it, but it gives me the error: "pip: not found."
That's right. If you inspect the contents of the /usr/bin directory of the pulled image, you will notice that there is no pip or pip3 there. So RUN ln -s /usr/bin/pip3 /usr/bin/pip line in your Dockerfile does nothing. Even when python3.6 gets installed in the container (after calling apt install software-properties-common -y), you do not get pip with it.
Solution: install pip
The following commands can be used to install python3.6 binary and the corresponding pip:
RUN apt-get update
RUN apt-get install python3-pip
This installs both python3.6 and pip3 in the /usr/bin directory of your ubuntu:18/04 container.
Issue 2: auto-sklearn requires python >= 3.7
Even if you manage to get both python3.6 and pip for python3.6, installation of auto-sklearn might still fail with the following error:
RuntimeError: Python version >= 3.7 required.
This is because some of the dependencies (e.g. ConfigSpace package) require python version >= 3.7.
Solution:
This answer explains how to install pip for python3.8 on Ubuntu: https://stackoverflow.com/a/63207387/15043192
You can follow it or get both pip and python3.8 installed using the following sequence:
Install python3.8:
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update
RUN apt install python3.8
Install python3.6 and pip for python3.6
RUN apt install python3-pip
Now if you execute python3.6 -m pip --version in the container, you would get something like (the version of pip might be different):
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
Install pip for python3.8
Note: here we use previously installed pip for python3.6 to install pip for python3.8. Do not ask me why :-)
RUN python3.8 -m pip install pip --upgrade
Install auto-sklearn
RUN python3.8 -m pip install auto-sklearn
Note: the command above might also install pandas package among other dependencies of auto-sklearn.
Create a symbolic link to python3.8
This would change the default
RUN ln -s /usr/bin/python3.8 /usr/bin/python
Now if you execute python -m pip --version in the container, you would get something like (the version of pip might be different):
pip 21.2.4 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
Grand finale:
In the end, your Dockerfile should look like this:
FROM ubuntu:18.04
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update
RUN apt install python3.8
RUN apt install python3-pip
RUN python3.8 -m pip install auto-sklearn
RUN python3.8 -m pip install pandas
RUN ln -s /usr/bin/python3.8 /usr/bin/python
ADD test.py /
CMD [ "python", "./test.py" ]
NB
To avoid messing around with different versions of python and pip, you might want to have a look into virtual environments.
I am trying to install gattlib in Python in order to use some of its Bluetooth-tools.
The OS is ubuntu 18.04.4 LTS.
I have by now tried the following (as e.g. here):
sudo apt-get install mercurial
hg clone https://bitbucket.org/OscarAcena/pygattlib
cd pygattlib
cat DEPENDS
sudo apt-get install libboost-thread-dev libboost-python-dev libbluetooth-dev libglib2.0-dev python-dev
sudo python3 setup.py install
which gives (my Python is 3.6.9):
usr/bin/ld: cannot find -lboost-python36
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-g++' failed with exit status 1
Also, I tried:
sudo apt install python3-gattlib
which gives:
the following packages have unmet dependencies:
python3-gattlib: Depends: python3 (>= 3.7~) but 3.6.7-1~18.04 is to be installed
Depends: libboost-python1.67.0 but is is not installable
Depends: libboost-thread1.67.0 but is is not installable
despite libboost-python and libboost-thread being successfully installed in the first attempt (see above), and python3 returning Python 3.6.9.
pip3 install gattlib
shows:
Building wheel for gattlib(setup.py) ... error
Running setup.py install for gattlib ... error
Which is the exact same result that I get from (following instructions from this question):
sudo pip3 download gattlib
sudo tar xvzf ./gattlib-0.20200122.tar.gz
cd gattlib-0.20200122/
sudo sed -ie 's/boost_python-py34/boost_python36/' setup.py
pip3 install .
in which I understand to be a necessary adjustment of the installation file before running it, because, if I understood correctly, the python version is somehow wrongly hardcoded in there.
Futher things I tried and that did not help:
pip3 install --upgrade setuptools
sudo apt-get install python3.6-dev libmysqlclient-dev
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo apt-get install libpython-dev
sudo apt-get install libevent-dev
sudo pip3 install gattlib
wget -qO- http://pike.esi.uclm.es/add-pike-repo.sh | sudo sh
sudo apt update
sudo apt install python3-gattlib
sudo apt-get install libbluetooth-dev
pip3 install --upgrade pip
sudo apt-get install mercurial
pip3 install gattlib
sudo apt-get install libboost-all-dev
cd /usr/lib/x86-64-linux-gnu
sudo ln -s libboost_python-py35.so libboost_python-py36.so
sudo apt-get install libbluetooth-dev bluez bluez-hcidump libboost-python-dev libboost-thread-dev libglib2.0-dev
hg clone https://bitbucket.org/OscarAcena/pygattlib
cd pygattlib
cat DEPENDS
sudo apt-get install libboost-thread-dev libboost-python-dev libbluetooth-dev libglib2.0-dev python-dev
sudo python3 setup.py install
sudo python setup.py install
pip3 install gTTS
sudo apt-get install python3 python-dev python3-dev \
build-essential libssl-dev libffi-dev \
libxml2-dev libxslt1-dev zlib1g-dev \
python-pip
sudo apt-get install aptitude
sudo aptitude install libboost-all-dev
I run
sudo python3 setup.py install
and I also get error
usr/bin/ld: cannot find -lboost-python36
because I don't have boost-python36.a but boost-python3-py36.a.
(I found this file using locate boost-python3 which uses database with filenames so it works faster then find but it may not be installed as default)
I had to edit setup.py and change
boost_libs = ["boost_python3"+str(sys.version_info.minor)]
to
boost_libs = ["boost_python3-py36"]
or more universal
boost_libs = ["boost_python3-py3"+str(sys.version_info.minor)]
Tested od Linux Mint 19.3 Tricia based on Ubuntu 18.04
You need to install python-dev that contains the header files for the Python C API. The following should do the trick (make sure to replace X with your Python version):
sudo apt-get install python3.X-dev
With ubuntu 20.04:
$ wget https://github.com/oscaracena/pygattlib/releases/download/v.20201113/python3-gattlib_0.20201113-1_amd64.deb
$ sudo apt install ./python3-gattlib*.deb
$ pip3 install gattlib
Reference:
https://pypi.org/project/gattlib/
NOTE: This didn't work for me!
sudo apt install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev
CentOS 7 already has Python2.7.5 stock installed. I am doing an online course that requires Python3.x installed. So these are the following steps i took to install Python3.7.3.rc1 :
$cd /usr/src
$sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3rc1.tgz
$sudo tar xzf Python-3.7.3rc1.tgz
$cd Python-3.7.3rc1
$sudo ./configure --enable-optimizations
$sudo make altinstall
$sudo rm /usr/src/Python-3.7.3rc1.tgz
$python3.7 --version
Python 3.7.3rc1
I followed these steps religiously from this link : https://tecadmin.net/install-python-3-7-on-centos/
During my course i was required to install pyperclip using pip.
So i did :
$python3.7 -m pip install pyperclip
/usr/local/bin/python3.7: No module named pip
Please suggest a method to install pip for Python3.7.3rc1.
You should have taken the default available python3, that is the python3.6 package in centos7
that would have been easier to setup rather than compile an unsupported version.
Suggest you install the supported python3 package in centos
Try doing yum install python36 from repository
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
Update yum package
sudo yum update
Install python36 along with pip
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
Below steps are for python3.7,
suggest avoiding unsupported packages.
Alternate Steps for pip setup for Centos
You need to install pip for python3.7 series
Step 1: First install the EPEL Repository
sudo yum install epel-release
Step 2: Installing pip
python37 -m pip
Step 3: Verify if pip was installed properly
pip --version
If the command not found error shows up, try
python37 -m ensurepip
I also as you said "followed these steps religiously from this link: https://tecadmin.net/install-python-3-7-on-centos/."
It was not an option for me to install python3.6, as I explicitly needed 3.7.
I was able to install using the following procedure:
# AFAIK, libffi-devel solved the "ModuleNotFoundError: No module named '_ctypes'" I had when I tried installing without it.
yum install libffi-devel
cd /usr/src
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar xzf Python-3.7.5.tgz
cd Python-3.7.5
./configure --enable-optimizations
make install # Or: make altinstall
python3 -V
pip3 --version
rm -f /usr/src/Python-3.7.5.tgz
What I changed from the referenced article is the version (3.7.5 instead of 3.7.4) and in addition installed "libffi-devel". It could be that this one would have solved on 3.7.4 as well.
For CentOS 6 and 7 you can run this:
sudo yum install python37-setuptools
sudo easy_install-3.7 pip
Edit: You should then be able to install using pip3 install <package>
I've installed Python 3.7 on my Ubuntu 18.04 machine. Following this instructions in case it's relevant:
Download : Python 3.7 from Python Website [1] ,on Desktop and manually
unzip it, on Desktop Installation : Open Terminal (ctrl +shift+T)
Go to the Extracted folder
$ cd ~/Desktop/Python-3.7.0
$ ./configure
$ make
$ sudo make install
Making Python 3.7 default Python :
$ sudo vim ~/.bashrc
press i
on the last and new line - Type
alias python= python3.7
press Esc
type - to save and exit vim
:wq
now type
$ source ~/.bashrc
From here: https://www.quora.com/How-can-I-upgrade-Python-3-6-to-3-7-in-Ubuntu-18-04
I've downloaded several modules through pip install module but when I try to import them, I get a ModuleNotFoundError: No module names 'xx'
So I did some research and apparently when used pip to install, it installed in the modules in previous version of Python.
Somewhere (probably a question in SO) I found a suggestion to install the module using python3.7 -m pip install module but then I get /usr/local/bin/python3.7: no module named pip.
Now I'm stuck, pip is installed, but apparently not for Python 3.7. I'm assuming that if I can install pip for Python 3.7, I can run the pip install command and get the modules I need.
If that is the case, how can I install pip for python 3.7, since it's already installed?
This is the best I have come up with:
I have installed python 3.7 successfully and I can install modules using pip (or pip3) but those modules are installed in Python 3.6 (Comes with ubuntu). Therefore I can't import those modules in python 3.7 (get a module not found)
Python 3.7 doesn't recognize pip/pip3, so I can't install through pip/pip3
I need python 3.7
In general, don't do this:
pip install package
because, as you have correctly noticed, it's not clear what Python version you're installing package for.
Instead, if you want to install package for Python 3.7, do this:
python3.7 -m pip install package
Replace package with the name of whatever you're trying to install.
Took me a surprisingly long time to figure it out, too. The docs about it are here.
Your other option is to set up a virtual environment. Once your virtual environment is active, executable names like python and pip will point to the correct ones.
A quick add-on to mpenkov's answer above (didn't want this to get lost in the comments)
For me, I had to install pip for 3.6 first
sudo apt install python3-pip
now you can install python 3.7
sudo apt install python3.7
and then I could install pip for 3.7
python3.7 -m pip install pip
and as a bonus, to install other modules just preface with
python3.7 -m pip install <module>
EDIT 1 (12/2019):
I know this is obvious for most. but if you want python 3.8, just substitute python3.8 in place of python3.7
EDIT 2 (5/2020):
For those that are able to upgrade, Python 3.8 is available out-of-the-box for Ubuntu 20.04 which was released a few weeks ago.
This works for me.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then this command with sudo:
python3.7 get-pip.py
Based on this instruction.
I used apt-get to install python3.7 in ubuntu18.04. The installations are as follows.
install python3.7
sudo apt-get install python3.7
install pip3. It should be noted that this may install pip3 for python3.6.
sudo apt-get install python3-pip
change the default of python3 for python3.7. This is where the magic is, which will make the pip3 refer to python3.7.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
Hope it works for you.
To install all currently supported python versions (python 3.6 is already pre-installed) including pip for Ubuntu 18.04 do the following:
To install python3.5 and python3.7, use the deadsnakes ppa:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5
sudo apt-get install python3.7
Install python2.7 via distribution packages:
sudo apt install python-minimal # on Ubuntu 18.04 python-minimal maps to python2.7
To install pip use:
sudo apt install python-pip # on Ubuntu 18.04 this refers to pip for python2.7
sudo apt install python3-pip # on Ubuntu 18.04 this refers to pip for python3.6
python3.5 -m pip install pip # this will install pip only for the current user
python3.7 -m pip install pip
I used it for setting up a CI-chain for a python project with tox and Jenkins.
Combining the answers from #mpenkon and #dangel, this is what worked for me:
sudo apt install python3-pip
python3.7 -m pip install pip
Step #1 is required (assuming you don't already have pip for python3) for step #2 to work. It uses pip for Python3.6 to install pip for Python 3.7 apparently.
When i use apt install python3-pip, i get a lot of packages need install, but i donot need them. So, i DO like this:
apt update
apt-get install python3-setuptools
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
rm -f get-pip.py
The following steps can be used:
sudo apt-get -y update
---------
sudo apt-get install python3.7
--------------
python3.7
-------------
curl -O https://bootstrap.pypa.io/get-pip.py
-----------------
sudo apt install python3-pip
-----------------
sudo apt install python3.7-venv
-----------------
python3.7 -m venv /home/ubuntu/app
-------------
cd app
----------------
source bin/activate
Install python pre-requisites
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Install python 3.7 (from ppa repository)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7
Install pip3.7
sudo apt install python3-pip
python3.7 -m pip install pip
Create python and pip alternatives
sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3.7 10
sudo update-alternatives --install /usr/local/bin/pip pip /home/your_username/.local/bin/pip3.7 10
Make changes
source ~/.bashrc
python --version
pip --version
For those who intend to use venv:
If you don't already have pip for Python 3:
sudo apt install python3-pip
Install venv package:
sudo apt install python3.7-venv
Create virtual environment (which will be bootstrapped with pip by default):
python3.7 -m venv /path/to/new/virtual/environment
To activate the virtual environment, source the appropriate script for the current shell, from the bin directory of the virtual environment. The appropriate scripts for the different shells are:
bash/zsh – activate
fish – activate.fish
csh/tcsh – activate.csh
For example, if using bash:
source /path/to/new/virtual/environment/bin/activate
Optionally, to update pip for the virtual environment (while it is activated):
pip install --upgrade pip
When you want to deactivate the virtual environment:
deactivate
I installed pip3 using
python3.7 -m pip install pip
But upon using pip3 to install other dependencies, it was using python3.6.
You can check the by typing pip3 --version
Hence, I used pip3 like this (stated in one of the above answers):
python3.7 -m pip install <module>
or use it like this:
python3.7 -m pip install -r requirements.txt
I made a bash alias for later use in ~/.bashrc file as alias pip3='python3.7 -m pip'. If you use alias, don't forget to source ~/.bashrc after making the changes and saving it.
How about simply
add-apt-repository ppa:deadsnakes/ppa
apt-get update
apt-get install python3.7-dev
alias pip3.7="python3.7 -m pip"
Now you have the command
pip3.7
separately from pip3.
curl https://bootstrap.pypa.io/get-pip.py | sudo python3.7
if all else fails.
pip3 not pip. You can create an alias like you did with python3 if you like.
I have python3.7 and I want to install pip. However when I do the following:
sudo apt install python3-pip
It seems to download python version 3.6 and pip for that. Is there a way to not download python3.6 and just download pip for python3.7? It seems rather strange that pip is download a whole other package.
Download get-pip file
$curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Install pip for python3.7
$python3.7 get-pip.py
Check versions for both
$python3.7 -V && pip3 -V
Output:
Python 3.7.3
pip 19.1.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)
if you check apt show python3-pip output you see it depends on python3:any (>= 3.4~) so it doesn't strictly say I need python3.6
I assume that you didn't install python3.7 using apt so as a result apt doesn't recognize that you have python3 and it tries to install it for you.
Deadsnakes
You can use a ppa called deadsnakes.
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7
Then check that is has been installed successfully by running python3.7 --version. To use pip you can run python3.7 -m pip install package.
Compiling from source
You can build Python by yourself, on Debian based systems you would do:
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
Download your preferred python version from https://www.python.org/ftp/python/
Then extract the tar archive and run make
./configure --enable-optimizations
make
sudo make altinstall
Then run python3.7 --version
try this.
python3.7 -m pip install pip