Pip: Why does pip3 says I am using version 8.1.1 when I am using version 9.0.1?

Created on 2 Oct 2017  路  12Comments  路  Source: pypa/pip

  • Pip version: 9.0.1
  • Python version: 3.5
  • Operating system: Ubuntu 16.04

Description:

I do not know why pip3 says that I am using pip version 8.1.1 when pip version 9.0.1 is installed. How do I fix this?

What I've run:

$ sudo -H pip3 install youtube-dl --upgrade
Requirement already up-to-date: youtube-dl in /usr/local/lib/python3.5/dist-packages
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ python -c "import pip; print(pip.__version__)"
9.0.1
$ python3 -c "import pip; print(pip.__version__)"
9.0.1
auto-locked support

Most helpful comment

Thank you @benoit-pierre, @davidhyman and @pfmoore for your explanations.

Below shows the results from the commands you have shared:

$ python -m site
sys.path = [
    '~',
    '/usr/lib/python2.7',
    '/usr/lib/python2.7/plat-x86_64-linux-gnu',
    '/usr/lib/python2.7/lib-tk',
    '/usr/lib/python2.7/lib-old',
    '/usr/lib/python2.7/lib-dynload',
    '~/.local/lib/python2.7/site-packages',
    '/usr/local/lib/python2.7/dist-packages',
    '/usr/lib/python2.7/dist-packages',
    '/usr/lib/python2.7/dist-packages/PILcompat',
    '/usr/lib/python2.7/dist-packages/gtk-2.0',
]
USER_BASE: '~/.local' (exists)
USER_SITE: '~/.local/lib/python2.7/site-packages' (exists)
ENABLE_USER_SITE: True
$ python3 -m site
sys.path = [
    '~',
    '/usr/lib/python35.zip',
    '/usr/lib/python3.5',
    '/usr/lib/python3.5/plat-x86_64-linux-gnu',
    '/usr/lib/python3.5/lib-dynload',
    '~/.local/lib/python3.5/site-packages',
    '/usr/local/lib/python3.5/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '~/.local' (exists)
USER_SITE: '~/.local/lib/python3.5/site-packages' (exists)
ENABLE_USER_SITE: True
$ pip --version
pip 9.0.1 from ~/.local/lib/python3.5/site-packages (python 3.5)
$ pip3 --version
pip 9.0.1 from ~/.local/lib/python3.5/site-packages (python 3.5)
$ sudo -H pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

I realized the following:

  1. There are 2 locations for python 3 site-packages. The same is true for python 2.7. One location is in /usr/lib and any package installation there is done by root or sudo. The other location is in ~/.local/lib and any installation there is done by user.
  2. During my youtube-dl installation, I did it as sudo. This meant that the installation was done in /usr/local/lib/python3.5/dist-packages and the installation comment that "You are was using pip version 8.1.1..." meant that the pip package for root user is dated and needs upgrading.
  3. When I ran python3 -c "import pip; print(pip.__version__) and got pip version 9.0.1, I did it as user. Consequently, that meant that user was using pip version 9.0.1.
  4. In short, the pip3 used by sudo and user, in my system, are of different versions. sudo is using version 8.1.1 and user is using version 9.0.1. I confirmed this by comparing the results from command pip3 --version and sudo -H pip3 --version (see above).

To upgrade the pip package that is used by sudo, I did the following:

$ sudo -H pip3 install --upgrade pip
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.3MB 1.5MB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-9.0.1
$ sudo -H pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ sudo -H pip3 --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)

Question: What does the installation message

Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr

mean?

@pfmoore I have also applied pip install --user. Thanks for this. I could not install youtube-dl locally initially, neither did I appreciate the intricacy related to package installation using pip. Got a handle on it now. After uninstalling youtube-dl in sudo, I did this:

$ pip3 install youtube-dl
Collecting youtube-dl
  Using cached youtube_dl-2017.10.1-py2.py3-none-any.whl
Installing collected packages: youtube-dl
Exception:
Traceback (most recent call last):
  File "~/.local/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "~/.local/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "~/.local/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "~/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "~/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "~/.local/lib/python3.5/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "~/.local/lib/python3.5/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "~/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/youtube_dl'
$ pip3 install youtube-dl --user
Collecting youtube-dl
  Using cached youtube_dl-2017.10.1-py2.py3-none-any.whl
Installing collected packages: youtube-dl
Successfully installed youtube-dl-2017.10.1

All 12 comments

Check your Python path: python -m site

There are a few things going on here -

  • $pythonpath is not the same as your system path, so 'import pip' could be fetching from elsewhere?
  • Try running pip --version on the command line
  • Try comparing your commands with running them using sudo -H again

One way of upgrading pip / setuptools would be to:
python -m pip install -U pip
but I'd try the other stuff first.

It's also worth noting that you are using sudo to run pip. This is typically a bad idea, as it modifies system-managed packages. In this situation, it's quite possible that you're getting a system version of pip from a directory different than the one you use when running as your own user.

To manage your system Python, you should use your distribution packages (apt-get). To manage your user installation of Python, use pip install --user or virtual environments.

In the case of youtube-dl, which is a standalone application packaged as a Python package, you may want to look into pipsi which handles the management of a virtualenv specific to the application for you.

Thank you @benoit-pierre, @davidhyman and @pfmoore for your explanations.

Below shows the results from the commands you have shared:

$ python -m site
sys.path = [
    '~',
    '/usr/lib/python2.7',
    '/usr/lib/python2.7/plat-x86_64-linux-gnu',
    '/usr/lib/python2.7/lib-tk',
    '/usr/lib/python2.7/lib-old',
    '/usr/lib/python2.7/lib-dynload',
    '~/.local/lib/python2.7/site-packages',
    '/usr/local/lib/python2.7/dist-packages',
    '/usr/lib/python2.7/dist-packages',
    '/usr/lib/python2.7/dist-packages/PILcompat',
    '/usr/lib/python2.7/dist-packages/gtk-2.0',
]
USER_BASE: '~/.local' (exists)
USER_SITE: '~/.local/lib/python2.7/site-packages' (exists)
ENABLE_USER_SITE: True
$ python3 -m site
sys.path = [
    '~',
    '/usr/lib/python35.zip',
    '/usr/lib/python3.5',
    '/usr/lib/python3.5/plat-x86_64-linux-gnu',
    '/usr/lib/python3.5/lib-dynload',
    '~/.local/lib/python3.5/site-packages',
    '/usr/local/lib/python3.5/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '~/.local' (exists)
USER_SITE: '~/.local/lib/python3.5/site-packages' (exists)
ENABLE_USER_SITE: True
$ pip --version
pip 9.0.1 from ~/.local/lib/python3.5/site-packages (python 3.5)
$ pip3 --version
pip 9.0.1 from ~/.local/lib/python3.5/site-packages (python 3.5)
$ sudo -H pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

I realized the following:

  1. There are 2 locations for python 3 site-packages. The same is true for python 2.7. One location is in /usr/lib and any package installation there is done by root or sudo. The other location is in ~/.local/lib and any installation there is done by user.
  2. During my youtube-dl installation, I did it as sudo. This meant that the installation was done in /usr/local/lib/python3.5/dist-packages and the installation comment that "You are was using pip version 8.1.1..." meant that the pip package for root user is dated and needs upgrading.
  3. When I ran python3 -c "import pip; print(pip.__version__) and got pip version 9.0.1, I did it as user. Consequently, that meant that user was using pip version 9.0.1.
  4. In short, the pip3 used by sudo and user, in my system, are of different versions. sudo is using version 8.1.1 and user is using version 9.0.1. I confirmed this by comparing the results from command pip3 --version and sudo -H pip3 --version (see above).

To upgrade the pip package that is used by sudo, I did the following:

$ sudo -H pip3 install --upgrade pip
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.3MB 1.5MB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-9.0.1
$ sudo -H pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ sudo -H pip3 --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)

Question: What does the installation message

Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr

mean?

@pfmoore I have also applied pip install --user. Thanks for this. I could not install youtube-dl locally initially, neither did I appreciate the intricacy related to package installation using pip. Got a handle on it now. After uninstalling youtube-dl in sudo, I did this:

$ pip3 install youtube-dl
Collecting youtube-dl
  Using cached youtube_dl-2017.10.1-py2.py3-none-any.whl
Installing collected packages: youtube-dl
Exception:
Traceback (most recent call last):
  File "~/.local/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "~/.local/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "~/.local/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "~/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "~/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "~/.local/lib/python3.5/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "~/.local/lib/python3.5/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "~/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/youtube_dl'
$ pip3 install youtube-dl --user
Collecting youtube-dl
  Using cached youtube_dl-2017.10.1-py2.py3-none-any.whl
Installing collected packages: youtube-dl
Successfully installed youtube-dl-2017.10.1

Question: What does the installation message

Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr

mean?

It means that when upgrading, pip would normally uninstall the old version, but in this case the old version was located in a place pip wasn't expecting, so it didn't do so. You may now have both pip 9.0.1 and pip 8.1.1 installations on your root PYTHONPATH. It's likely that this won't stop pip working, but it may cause odd issues in the future (e.g. when upgrading).

This nicely illustrates why you should not use sudo pip to manage system packages, as Debian/Ubuntu patch their copy of pip to include the dist-packages directory somehow and the standard pip does not understand this convention. You should always manage your system packages using the system tools (apt in this case) - I would expect apt-get to understand the dist-packages directory and handle it properly.

To clean up your system install, you may be able to pip uninstall your upgraded copy of pip and then apt-get update or repair the OS pip package. But I can't be sure of that (as I'm not an Ubuntu user). If you hit difficulties, you'll probably need to ask for help on an Ubuntu forum.

@pfmoore Just when I thought I got a better handle of this topic, your explanation showed me I did not. I am grateful for your explanations. :)

I have uninstalled the pip package that I recently installed via the pip3 command as sudo -H.

sudo -H pip3 uninstall pip
Uninstalling pip-9.0.1:
  /usr/bin/pip3
  /usr/local/bin/pip
  /usr/local/bin/pip3
  /usr/local/bin/pip3.5
  /usr/local/lib/python3.5/dist-packages/pip-9.0.1.dist-info/DESCRIPTION.rst
  ----
Proceed (y/n)? y
  Successfully uninstalled pip-9.0.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I had thought that the pip package version 8.1.1 was available but like what you said there could be issue caused by what I did, and you were right.

sudo -H pip3 --version
sudo: pip3: command not found

To solve my problem, I used Synaptic Package Manager to view my system level pip installation. python3-pip, the system level pip package, was shown to be installed although it was non-responsive. Reinstallation did not yield any responsiveness either. I therefore did a complete removal of the python3-pip package and reinstall it thereafter.

$ sudo pip3 --version
pip 9.0.1 from ~/.local/lib/python3.5/site-packages (python 3.5)
$ sudo -H pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

From the above, I think the pip installation at the system level has been restored. It shows that if pip is executed as sudo it will use the pip package installed in the user's local directory, and if pip is executed as sudo -H it will use the system level pip package. It seems that for Ubuntu 16.04.3, which I am using, the system level pip version is dated, which means I will have to continue to enjoy having the reminder that the system level pip package is dated whenever I use the pip command. Correct?

Complain to Ubuntu that they don't have the latest pip? :wink:

You might be able to use the --disable-pip-version-check option to avoid the warning - but I don't know how you'd set things up to say "only do this for the system pip, not for ones I have in my virtualenvs or locally installed, ...". Probably not worth the effort, you may as well just live with the message and avoid using the system pip as much as you can.

Thanks! ;)

python -m pip install -U pip
worked for me.
Thanks

I encountered problem using the -U. Instead I had to use the --user option:
$ python3 -m pip install --user --upgrade pip

Don't work:

$ python3 -m pip install -U --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 18.0
    Uninstalling pip-18.0:
      Successfully uninstalled pip-18.0
  Rolling back uninstall of pip
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/pip-18.1.dist-info'
Consider using the `--user` option or check the permissions.

You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Works:

$ python3 -m pip install --user --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 18.0
    Uninstalling pip-18.0:
      Successfully uninstalled pip-18.0
Successfully installed pip-18.1

Simply use 'SUDO' before the command.

Best

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings