surroundings
pippip versionpip3.1. Normal update
3.2. Can't update, install and update through source code
3.2.1 Download source code
3.2.2 Unzip and install
3.2.3 I updated to the latest version, but I get the error ImportError: cannot import name main
pip pip commonly used commandsubuntu 16.04python2.7.12pipapt-get install python-pip
# Of course you can install other things together
apt-get install python-pip python-dev build-essential
pip version## Capital V, or--version
pip -V
# Output:
# pip 8.1.1from/usr/lib/python2.7/dist-packages(python 2.7)
pippip 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.
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.
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
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
ImportError: cannot import name mainUse 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.
pipapt-get remove python-pip
pipCommon Commands#pip help: pip -helppython package: pip install packageNamepython package: pip uninstall packageNamepython package: pip search packageNamepip installation package of python2: pip listpip installation package of python3: pip3 listOK!
Above, Enjoy~
Recommended Posts