[Linux] Ubuntu install pip and its various bug solutions

Original article http://blog.csdn.net/humanking7/https://blog.csdn.net/humanking7/article/details/84392790

Article Directory###

surroundings#

1. Install pip

apt-get install python-pip

# Of course you can install other things together
apt-get install python-pip python-dev build-essential

2. View pip version#

# Capital V, or--version
pip -V 
# Output:
# pip 8.1.1from/usr/lib/python2.7/dist-packages(python 2.7)

3. Update pip

3.1. Normal update##

pip install --upgrade pip
# or
pip install -U pip

But it may not be able to upgrade, it shows:

root@qfx-HP-xw4600-Workstation:~# pip install -U 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 8.1.1
 Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

3.2. Can't update, install and update through source code##

I have tried various methods, such as using the command: python -m pip install --upgrade pip to install, but the above prompt will still appear, so use the source code to upgrade.

3.2.1 Download source code###

Download the source code, or go to the official website of pip to download https://pypi.org/project/pip/#files

wget https://files.pythonhosted.org/packages/45/ae/8a0ad77defb7cc903f09e551d88b443304a9bd6e6f124e75c0fbbf6de8f7/pip-18.1.tar.gz
# ==========
# Detailed installation information
root@qfx-HP-xw4600-Workstation:~# mkdir pipDir
root@qfx-HP-xw4600-Workstation:~# cd pipDir/
root@qfx-HP-xw4600-Workstation:~/pipDir# wget https://files.pythonhosted.org/packages/45/ae/8a0ad77defb7cc903f09e551d88b443304a9bd6e6f124e75c0fbbf6de8f7/pip-18.1.tar.gz
- - 2018- 11- 2313:56:53- - https://files.pythonhosted.org/packages/45/ae/8a0ad77defb7cc903f09e551d88b443304a9bd6e6f124e75c0fbbf6de8f7/pip-18.1.tar.gz
Parsing host files.pythonhosted.org(files.pythonhosted.org)... 2a04:4e42:1a::319,151.101.109.63
Connecting files.pythonhosted.org(files.pythonhosted.org)|2a04:4e42:1a::319|:443...connected.
HTTP request has been sent, waiting for response...200 OK
Length: 1259370(1.2M)[binary/octet-stream]
Saving to: “pip-18.1.tar.gz”

pip-18.1.tar.gz           100%[====================================>]1.20M  9.92KB/s    in 2m 35s  

2018- 11- 2313:59:31(7.94 KB/s)-Saved "pip-18.1.tar.gz” [1259370/1259370])

root@qfx-HP-xw4600-Workstation:~/pipDir# ls
pip-18.1.tar.gz

3.2.2 Unzip and install###

Unzip and install

# Unzip
root@qfx-HP-xw4600-Workstation:~/pipDir# tar xzvf pip-18.1.tar.gz 
# View the unzipped directory
root@qfx-HP-xw4600-Workstation:~/pipDir# ls
pip-18.1  pip-18.1.tar.gz
# Enter the directory to view the files inside
root@qfx-HP-xw4600-Workstation:~/pipDir# cd pip-18.1/
root@qfx-HP-xw4600-Workstation:~/pipDir/pip-18.1# ls -1
AUTHORS.txt
docs
LICENSE.txt
MANIFEST.in
NEWS.rst
PKG-INFO
pyproject.toml
README.rst
setup.cfg
setup.py
src
# Install pip
root@qfx-HP-xw4600-Workstation:~/pipDir/pip-18.1# python setup.py install
......

Installed /usr/local/lib/python2.7/dist-packages/pip-18.1-py2.7.egg
Processing dependencies for pip==18.1
Finished processing dependencies for pip==18.1
# This means the installation was successful

3.2.3 I updated to the latest version, but I get an error ImportError: cannot import name main

Use pip -V to check the version and find an error:

root@qfx-HP-xw4600-Workstation:~/pipDir/pip-18.1# pip -V
Traceback(most recent call last):
 File "/usr/bin/pip", line 9,in<module>from pip import main
ImportError: cannot import name main

The reason for the problem:
It is said to be a bug. As long as you use pip, an exception will be thrown, but it is easier to solve.

First locate the problem:
The problem occurs in the pip file in /usr/bin/, open it with vim and edit it:
Original code:

#! /usr/bin/python
# GENERATED BY DEBIAN

import sys 

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.from pip import main
if __name__ =='__main__':
 sys.exit(main())

Modified code:

#! /usr/bin/python
# GENERATED BY DEBIAN

import sys 

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.from pip import __main__
# from pip import main
if __name__ =='__main__':
 sys.exit(__main__._main())
 # sys.exit(main())

After saving, check the current version of pip:

root@qfx-HP-xw4600-Workstation:~/pipDir/pip-18.1# pip -V
pip 18.1from/usr/local/lib/python2.7/dist-packages/pip-18.1-py2.7.egg/pip(python 2.7)

ok, it has been successfully updated to pip 18.1.

4. Uninstall pip

apt-get remove python-pip

5. pipCommon Commands#


OK!
Above, Enjoy~

Recommended Posts

[Linux] Ubuntu install pip and its various bug solutions
Linux install Docker and run Ubuntu system
Install and use Git and GitHub on Ubuntu Linux
[Linux] ubuntu install configuration vsftpd and lock the directory
Windows 10 install Linux subsystem Ubuntu
Ubuntu 16.04 compile and install PHP 7.2
2.5 Linux (Ubuntu18.04) install database PostgreSQL
ubuntu18.04 compile and install python3.8
ubuntu install and configure GitLab
CentOS7 install python3 and pip3
Ubuntu16.04 install SVN and configuration
Ubuntu16.04 install and uninstall VMware-Workstation 14
Ubuntu pip3 install uwsgi error
Talk about | Install and use Linux system Ubuntu under Win10
Deep learning to install Keras and its dependencies on Ubuntu
How to install JDK and Mysql on Ubuntu 18.04 linux system
Install and configure MySQL on Ubuntu
Install and configure Docker in Ubuntu
CentOS quickly install Python3 and pip3
Install and deploy Gerrit under Ubuntu
Install nodejs and npm under Ubuntu 16.04
Linux CentOS6 compile and install Pyt
Compile and install QEMU under Ubuntu
Linux basics (Ubuntu copy and paste)
Install Gnome and VNC on Ubuntu Server
Linux development preparation-install VMware and run Ubuntu
Install linux (ubuntu) dual system under windows system
[Daily] Win10 open and install ubuntu subsystem
Ubuntu install Elasticsearch and elasticsearch-analysis-ik word segmentation
How to install MySQL on Ubuntu 18.04 (linux)
Install docker on ubuntu and basic usage
Install fonts on Ubuntu and switch default fonts
Ubuntu 18.04 source code compile and install ffmpeg4.1
Ubuntu install PHP and PHP Nginx configuration method
Windows 10 subsystem linux install pagoda panel Ubuntu
Install and uninstall CUDA and CUDNN on Ubuntu
Ubuntu 14.04 16.04 Linux nvidia driver download and installation
Ubuntu install ftp server and possible problems
How to install Ubuntu20.04 and install NVIDIA driver
Linux (ubuntu 12.04)
How to install vim editor under Linux (Ubuntu 18.04)
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure NATS on Ubuntu 16.04
Install JDK and configure environment variables on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and use Docker on Ubuntu 20.04
How to install and configure Ansible on Ubuntu 18.04
Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
Simple and clean install remote login for ubuntu18
Win10 install Linux ubuntu-18.04 dual system (installation guide)