转载自https://blog.csdn.net/qq_41917697/article/details/114400002
ubuntu16.04的python2没有pip模块,python2安装pip2:
haypin@ubt:~/catkin_ws/src$ curl https://bootstrap.pypa.io/2.7/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 936 100 936 0 0 522 0 0:00:01 0:00:01 --:--:-- 522
haypin@ubt:~/catkin_ws/src$ ls
beginner_tutorials CMakeLists.txt get-pip.py package_manager water_scripts water_test
haypin@ubt:~/catkin_ws/src$ python2 get-pip.py
Hi there!
The URL you are using to fetch this script has changed, and this one will no
longer work. Please use get-pip.py from the following URL instead:
https://bootstrap.pypa.io/pip/2.7/get-pip.py
Sorry if this change causes any inconvenience for you!
We don't have a good mechanism to make more gradual changes here, and this
renaming is a part of an effort to make it easier to us to update these
scripts, when there's a pip release. It's also essential for improving how we
handle the `get-pip.py` scripts, when pip drops support for a Python minor
version.
There are no more renames/URL changes planned, and we don't expect that a need
would arise to do this again in the near future.
Thanks for understanding!
- Pradyun, on behalf of the volunteers who maintain pip.
haypin@ubt:~/catkin_ws/src$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1863k 100 1863k 0 0 4654 0 0:06:50 0:06:49 0:00:01 14070
haypin@ubt:~/catkin_ws/src$ python2 get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting pip<21.0
Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 19 kB/s
Collecting wheel
Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, wheel
Successfully installed pip-20.3.4 wheel-0.36.2
haypin@ubt:~/catkin_ws/src$ python2 -m pip -V
pip 20.3.4 from /home/haypin/.local/lib/python2.7/site-packages/pip (python 2.7)
haypin@ubt:~/catkin_ws/src$
python3升级pip3
haypin@ubt:~/catkin_ws/src$ python3 -m pip install --upgrade pip --force-reinstall #不要这样做,安装的pip-8.1.1版本很低,使用还会出错
Collecting pip
Downloading https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5MB)
100% |████████████████████████████████| 1.5MB 21kB/s
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
haypin@ubt:~/catkin_ws/src$
haypin@ubt:~/catkin_ws/src$ python3 -m pip install --upgrade pip #pip-8.1.1升级会出错
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/haypin/.local/lib/python3.5/site-packages/pip/__main__.py", line 21, in <module>
from pip._internal.cli.main import main as _main
File "/home/haypin/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
haypin@ubt:~/catkin_ws/src$
还升级错了?那按照上面Python2安装pip2的方式重装一下python3的pip模块:
haypin@ubt:~$ python3 --version
Python 3.5.2
haypin@ubt:~$ curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1863k 100 1863k 0 0 33994 0 0:00:56 0:00:56 --:--:-- 27178
haypin@ubt:~$ ls
catkin_ws Documents examples.desktop Pictures Redis_download Templates
cpptest Downloads get-pip.py Public rosbag_replay Videos
Desktop dump.rdb Music pytest ssh_codechina VMwares
haypin@ubt:~$ python3 get-pip.py
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting pip<21.0
Using cached pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.0.1
Uninstalling pip-21.0.1:
Successfully uninstalled pip-21.0.1
Successfully installed pip-20.3.4
haypin@ubt:~$
haypin@ubt:~$ python3 -m pip -V
pip 20.3.4 from /home/haypin/.local/lib/python3.5/site-packages/pip (python 3.5)
haypin@ubt:~$