Installing pip on ubuntu 16.04 - python

I was installing pip for python3. I used the following command for that:
sudo apt-get install python3-pip
But after installation it still says pip is not installed.
I have python 3.5.2 installed.

The python3-pip package installs pip for Python 3, which is named pip3. Plain pip is pip for Python 2, which is installed by the python-pip package.

The best way to install it, is by :
wget https://bootstrap.pypa.io/get-pip.py
cd ~/Downloads/ (if your version is english, in french you find it Téléchargements)
Then once you downloaded it, try :
sudo python3 get-pip.py

easy_install -U pip : this solved my problem on ubuntu 16.04

Related

How do I install pip for python 3.8 on Ubuntu without changing any defaults?

I'm trying to install pip for Python 3.8 on an Ubuntu 18.04 LTS.
I know this has been asked way too many times. But those questions do not concern keeping Ubuntu's defaults specifically. And the answers on those questions either don't work or go on to suggest something so drastic that it would break the system - e.g. change default python3 version from 3.6 to 3.8. You SHOULDN'T!
So far, I've been able to install python3.8 successfully using the PPA - ppa:deadsnakes/ppa:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8
Changed python command from python2 to python3.8 using update-alternatives:
update-alternatives --remove python /usr/bin/python2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10
Now, I get python 3.8 when I run python --version:
Python 3.8.5
The problem is, I still can't install pip for Python 3.8.
If I try to install python3-pip, it installs pip for Python 3.6 since python3 still points to python3.6.9, and I intend to keep it that way.
Try installing python-pip, and it will install pip for Python 2.7.
Also there's no such package as python3.8-pip, so I can't install it like:
sudo apt install python3.8-pip
Output:
E: Unable to locate package python3.8-pip
E: Couldn't find any package by glob 'python3.8-pip'
E: Couldn't find any package by regex 'python3.8-pip'
What can I do to install pip for Python 3.8 on an Ubuntu 18.04?
While we can use pip directly as a Python module (the recommended way):
python -m pip --version
This is how I installed it (so it can be called directly):
Firstly, make sure that command pip is available and it isn't being used by pip for Python 2.7
sudo apt remove python-pip
Now if you write pip in the Terminal, you'll get that nothing is installed there:
pip --version
Output:
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
Install python3.8 and setup up correct version on python command using update-alternatives (as done in the question).
Make sure, you have python3-pip installed:
(This won't work without python3-pip. Although this will install pip 9.0.1 from python 3.6, we'll need it.)
sudo apt install python3-pip
This will install pip 9.0.1 as pip3:
pip3 --version
Output:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
Now, to install pip for Python 3.8, I used pip by calling it as a python module (ironic!):
python -m pip install pip
Output:
Collecting pip
  Downloading https://files.pythonhosted.org/packages/36/74/38c2410d688ac7b48afa07d413674afc1f903c1c1f854de51dc8eb2367a5/pip-20.2-py2.py3-none-any.whl (1.5MB)
  100% |████████████████████████████████| 1.5MB 288kB/s
Installing collected packages: pip
Successfully installed pip-20.2
It looks like, when I called pip (which was installed for Python 3.6, BTW) as a module of Python 3.8, and installed pip, it actually worked.
Now, make sure your ~/.local/bin directory is set in PATH environment variable:
Open ~/.bashrc using your favourite editor (if you're using zsh, replace .bashrc with .zshrc)
nano ~/.bashrc
And paste the following at the end of the file
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
Finally, source your .bashrc (or restart the Terminal window):
source ~/.bashrc
Now if you try running pip directly it'll give you the correct version:
pip --version
Output:
pip 20.2 from /home/qumber/.local/lib/python3.8/site-packages/pip (python 3.8)
Sweet!
As suggested in official documentation you can try with get-pip.py.
wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py
This will install pip as pip3.8
Another solution would be to install the pip that is in apt. sudo apt install python3-pip. The version of the pip that it installs is for all versions of Python not only for version 3.6 once installed you just need to update the pip with the command python3.8 -m pip install pip and he will be install the latest version of pip for Python.
I would not advise you to remove Python2 because it is an important module for the system you should just create a permanent "alias" in .bashrc for Python3 I did like this alias python="python3.8.
# install py3.8 and dependencies for the pip3 bootstrap script
add-apt-repository -y ppa:deadsnakes/ppa && \
apt install -y python3.8 python3.8-distutils
# download and run the pip3 bootstrap script
cd /tmp && wget https://bootstrap.pypa.io/get-pip.py && \
python3.8 /tmp/get-pip.py
# use pip py3.8 module to install python packages
python3.8 -m pip install numpy pandas
Install python v3.8 as python
RUN apt update --fix-missing && \
apt install python3.8 -y && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10
Install pip for python 3.8
RUN apt install python3-pip -y && \
python -m pip install --upgrade pip
I did this a couple days ago and I struggled a lot with it but I finally got it working, so I wrote up what I did as a blog post.
In the end I think I may have done mostly the same things as the above answer, but if you got lost following it, maybe my screenshots etc will help.
Here's the tl;dr of the process I did:
Uninstall python3-pip & python-pip using apt
Remove the old pip files from /usr/local/bin
Reinstall python3-pip using apt
Add $HOME/.local/bin to your $PATH (also restart your shell to make sure you did this right)
On ubuntu server
sudo apt install python -y
For more information check this blog here.
https://teckresolve.com/install-python-packages-using-pip/

Pip Install keeps installing libraries to Python2.7 rather than Python3

I'm trying to install modules such as gitpython into my Python3 directory however when I run:
Pip install gitpython it automatically downloads it into python2.7
I've tried specify the Python3 directory but it says the the library has already been installed.
Requirement already satisfied: gitpython in /usr/local/lib/python2.7/dist-packages (2.1.11)
Problem is when I try to call from git import repo my Python3 can't find the module.
Is there anyway to get pip to install my libraries to Python3 as a default, can I just uninstall Python 2.7 to save problems?
I run
sudo apt install python3-pip
and it states it is already installed, so I run sudo pip3 install gitpython and it says Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
SOLUTION
sudo apt-get remove python3-pip; sudo apt-get install python3-pip
It depends of your version of pip. But I think that python3-pip may do the trick.
sudo apt-get install python3-pip
sudo pip3 install MODULE_NAME
You should use pip3 to install your packages in your python3 environment. thus instead of installing with pip use pip3 install gitpython
You can try to see the version of python with:
python --version
if the result is python 2.7, that means that your environment variable for python3 needs to be set.
After that you can try:
python -m pip install package_name
I hope it will help you =)
Adrien
You should use python3 venv Python 3 venv
python3 -m venv /path/virtual/environment
source /path/virtual/environment/bin/activate
or use pip3 to installing any libraries for python 3
$ pip3 install 'some library'
You should create virtual environment for python3. using:
virtualenv -p /usr/bin/python3 <VIRTUAL_ENV NAME>
Then activate it using:
source <VIRTUAL_ENV NAME>/bin/activate
Then install your dependency(gitpython in your case) into that.

How to Install pip for python 3.7 on Ubuntu 18?

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.

Recommended way to install pip(3) on centos7

I am interrested in knowing the recommended way to install pip3 for python3.6 (as of today, may 2018) on current version of centos7 (7.5.1804) and the accepted answer of How to install pip in CentOS 7? seems to be outdated because:
yum search -v pip
outputs (among other things):
python2-pip.noarch : A tool for installing and managing Python 2 packages
Repo : epel
python34-pip.noarch : A tool for installing and managing Python3 packages
Repo : epel
and python34-pip seems to be a (newer?) simpler way than the accepted answer of How to install pip in CentOS 7? :
sudo yum install python34-setuptools
sudo easy_install-3.4 pip
But since the versions of python installed on my machine are 2.7.5 and 3.6.3 why is it python34-pip and not python36-pip ? Is pip the same for 3.4+ (up to current 3.6.3) ?
Is pip the same for 3.4+
No, it's not. A single pip installation serves a single Python distribution (pip2.7/pip3.4/pip3.5 etc).
Since Python 3.5, pip is already bundled with the python distribution, so you can just run python3.6 -m pip instead of pip.
Python 3.6 is not available in CentOS 7 vanilla repo. I usually resort to IUS repo when needing to install a fresh Python on CentOS. It always has the most recent Python version, the current one being 3.6.5. It also offers a correspondent pip package.
$ yum install https://centos7.iuscommunity.org/ius-release.rpm
$ yum install python36u python36u-devel python36u-pip
Unfortunately, IUS doesn't offer a package for Python 3.7 yet so if you are looking for Python 3.7 on CentOS 7, building from source is your only option.
Edit: when yum is not an option
You should prefer the bootstrapping solution described in this answer as it is the most reliable way to get a working pip installed.
To install pip for python 3.6 on CentOS 7 you need to run
$ python3.6 -m ensurepip
Follow these commands in Centos 7
yum install python36
yum install python36-devel
yum install python36-setuptools
easy_install-3.6 pip
to check the pip version:
pip3 -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)
There is now a python3-pip package in the CentOS 7 base repository as of 2019-08-22. There is no longer a need for third-party repositories or packages.
Installing python3-pip will also install libtirpc, python3, python3-libs, and python3-setuptools:
yum install --assumeyes python3-pip
You can now verify the version (yes, it is old, but it's what is coming from the base repository):
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
If you don't want to stray from the files provided by the python3-pip package, and you don't want to see warnings about pip being old, see https://stackoverflow.com/a/46288945/534275 for silencing the messages.
Pip is not bundled in the EPEL version of python 3.6 for some reason. I assume a decent amount of people (such as me) will find this page because of that.
$ sudo yum install -y python36
...
$ python36 -m pip
/usr/bin/python36: No module named pip
So in this case, the setuptools package was the easiest solution.
$ sudo yum install python36-setuptools
$ sudo easy_install-3.6 pip
...
$ python36 -m pip --version
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)
In case you're seeing that pip3 is linked to python2 path:
$ pip3 -V
pip 8.1.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)
You'll probably get:
$ pip3 install --upgrade pip
TypeError: parse() got an unexpected keyword argument 'transport_encoding'
Then try to clear commands cache with hash -r. This has worked for me:
# Install Python 3:
sudo yum install python36 -y
# Install & Upgrade pip3
sudo python36 -m pip install --upgrade pip
# Validate pip3 installation:
sudo python3.6 -m ensurepip
# Successfully installed pip-10.0.1 setuptools-39.0.1
# Clear commands cache
hash -r
# might be required if getting in bash: /usr/bin/pip3: No such file or directory)
pip3 -V
# pip 19.0.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
which pip3
# /usr/local/bin/pip3
pip2 -V
# pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
which pip2
# /usr/local/bin/pip2
# Install your Python3 module:
sudo /usr/local/bin/pip3 install {required module for python3}
I got this error when I tried to install python36 over the built-in centos7 python 2.7.5 version:
Transaction check error:
file /etc/rpm/macros.python from install of python-rpm-macros-3-32.el7.noarch conflicts with file from package python-devel-2.7.5-80.el7_6.x86_64
And I fixed it with these:
yum install python36
yum update python-devel
yum install python36-devel
easy_install-3.6 pip
Try This::
sudo yum update
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
Working for me perfectly.

Installing python module when there are two versions of python installed

I am using ubundu and have python 2X and 3X installed, default version is python 2X. I want to install a package for python3X. When i tried doing it with pip the module got installed to python 2X
Use pip3:
sudo pip3 install 'module'
To install pip3:
sudo apt-get install python3-pip
e.g,:
python3.5 -m pip install mypackagename

Categories

Resources