一、参考资料
二、安装pip包
如何在 Ubuntu 20.04 上安装 Python Pip - 知乎 (zhihu.com)
1. 离线安装
1.1 为 Python 3 安装 pip
方式一
# 下载get-pip.py脚本 wget https://bootstrap.pypa.io/pip/3.6/get-pip.py 或者 # 下载最新版本 curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py # 为 Python 3 安装 pip sudo python3 get-pip.py
讯享网
方式二
讯享网# 下载tar.gz安装包 tar -xzvf pip-22.3.1.tar.gz # 解压 tar -xzvf pip-22.3.1.tar.gz # 安装pip3 sudo python3 setup.py install # 检查pip3版本号 pip –version
1.2 为 Python 2 安装 pip
# 下载get-pip.py脚本 curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py # 为 Python 2 安装 pip sudo python2 get-pip.py
2. 在线安装
2.1 为 Python 3 安装 pip
讯享网# 更新软件包索引,安装pip sudo apt-get update sudo apt-get install python3-pip # 查看pip3版本 pip3 --version
2.2 为 Python 2 安装 pip
# 启用 universe 源仓库 sudo add-apt-repository universe # 更新软件包索引,安装Python2 sudo apt update sudo apt install python2 # 查看pip版本 pip2 --version
3. 升级pip
讯享网# 升级pip,--upgrade 可简写为 -U sudo pip3 install --upgrade pip 或者 python3 -m pip install --upgrade pip
4. 卸载pip3
# 卸载pip3 sudo apt-get remove python-pip3 或者 sudo apt-get remove python3-pip
5. pip安装方式对比
5.1 从PyPI安装
讯享网# From PyPI: pip install dm-tree
5.2 从github安装
# Directly from github using pip: pip install git+git://github.com/deepmind/tree.git
5.3 从源码安装
讯享网# Build from source: # 下载地址:https://pypi.org/project/Tree tar -xvzf Tree-0.2.4.tar.gz python setup.py install
5.4 从whl安装
# 下载whl安装包 numpy-1.24.1-pp38-pypy38_pp73-win_amd64.whl # 解压,进入文件夹 pip install numpy-1.24.1-pp38-pypy38_pp73-win_amd64.whl
三、pip常用命令
1. --user安装
讯享网# 代表进行全局安装,安装后全局可用。如果是信任的安装包可用使用该命令进行安装。 sudo pip3 install # 代表仅该用户的安装,安装后仅该用户可用。处于安全考虑,建议使用该命令进行安装。 pip3 install --user
2. pip install
# 用pip3安装包 pip3 install 包名 # 非root用户安装,安装到用户目录,包会安装到用户目录下 pip3 install 包名 --user # 离线安装 pip3 install ./downloads/SomeProject-1.0.4.tar.gz
讯享网# 安装最新版本 pip3 install 包名 # 安装指定版本 pip3 install 包名==1.8 # 安装最小版本 pip3 install 包名>=1.8 # 安装 PIP 包,建议增加 --no-cache-dir 参数禁用本地缓存 pip install flask --no-cache-dir # 忽略包是否安装,都重新安装 pip3 install 包名 --ignore-installed # 设置超时连接时间为60s,默认为15s pip3 install 包名 --timeout=60 # 安装到指定位置 pip3 install 包名 -t /PATH/TO/××× # 每次调用包的时候,需要加载该路径下的包 import sys sys.path.append('/PATH/TO/×××')
# freeze输出安装包 # 输出到requirements.txt文件中 pip3 freeze > requirements.txt # 通过requirements文件批量安装 pip3 install -r requirements.txt # 强烈推荐:批量安装跳过无法安装的包继续运行 while read requirement; do sudo pip3 install $requirement -i https://mirrors.aliyun.com/pypi/simple/; done < requirement.txt
讯享网# 更新版本,--upgrade 可简写为 -U pip3 install --upgrade 包名 # 如果更新失败,尝试添加 --ignore-installed pip3 install --upgrade --ignore-installed 包名 # 卸载包 pip3 uninstall 包名
镜像源
阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣(douban) http://pypi.douban.com/simple/ 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ Pypi官方 https://pypi.org/simple/
讯享网# 使用国内镜像安装,--index-url 简写为 -i pip3 install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple/ 或者 sudo pip3 install --index-url https://mirrors.aliyun.com/pypi/simple tensorflow-gpu==1.14 # 使用清华源升级pip sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
3. 设置pip与python版本
# 1. 查看pip2路径 which pip 输出: /usr/bin/pip # 2. 查看pip3路径 which pip3 输出: /usr/bin/pip3 # 3. 查看python2的路径 which python2 输出: /usr/bin/python2 # 4. 查看python3的路径 which python3 输出: /usr/bin/python3
讯享网# 5. 修改pip2对应python2 sudo gedit /usr/bin/pip # 第一行,改为: #!/usr/bin/python2 # 6. 修改pip3对应python3 sudo gedit /usr/bin/pip3 # 第一行,改为: #!/usr/bin/python3
4. 其他指令
# 从 git 安装 pip3 install -e git+https://git.repo/some_pkg.git#egg=SomeProject # 从 mercurial 安装 pip3 install -e hg+https://hg.repo/some_pkg#egg=SomeProject # 从 svn 安装 pip3 install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject # 安装某一分支 branch pip3 install -e git+https://git.repo/some_pkg.git@feature#egg=SomeProject
讯享网# show显示包的版本信息,依赖关系,安装位置等信息 pip3 show 包名 # search根据关键字搜索包 # 截止到2021年10月18日,官网暂时关掉了该功能 https://status.python.org/ # 搜索关键字,会列出所有与关键字相关的软件包 pip3 search 关键字
四、FAQ
Q: pip内部错误
python pip 错误 ModuleNotFoundError: No module named pip._internal 解决办法
pip错误 ImportError: No module named _internal Traceback (most recent call last): File "/home/ubuntu/.local/bin/pip", line 7, in <module> from pip._internal import main ImportError: No module named _internal
讯享网解决方案: 强制重新安装pip3 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate sudo python3 get-pip.py --force-reinstall
Q:ImportError: No module named pip._internal.cli.main
yoyo@yoyo:/opt/ros/kinetic/lib$ pip list Traceback (most recent call last): File "/home/yoyo/.local/bin/pip", line 5, in <module> from pip._internal.cli.main import main ImportError: No module named pip._internal.cli.main
Q: pip下载超时
PIP安装超时的解决方案
Q: pip2安装包失败
python2 中使用pip2 install package_name的时候报错:AttributeError: ‘int‘ object has no attribute ‘endswith‘

讯享网Traceback (most recent call last): File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py", line 290, in run with self._build_session(options) as session: File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 69, in _build_session if options.cache_dir else None File "/media/mydisk/MyDocuments/PyProjects/automl/efficientdet/venv/lib/python2.7/posixpath.py", line 70, in join elif path == '' or path.endswith('/'): AttributeError: 'int' object has no attribute 'endswith'
解决办法: 在使用pip2安装命令之前设置:PIP_NO_CACHE_DIR=off 比如: PIP_NO_CACHE_DIR=off pip2 install -U pip2
Q: pip版本太低了
TypeError: expected str, bytes or os.PathLike object, not int(解决方法)
讯享网Exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 290, in run with self._build_session(options) as session: File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 69, in _build_session if options.cache_dir else None File "/usr/lib/python3.6/posixpath.py", line 80, in join a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not int
解决办法: 升级pip 对于python2: curl https://bootstrap.pypa.io/get-pip.py | python2 - 对于python3: curl https://bootstrap.pypa.io/get-pip.py | python3 -
讯享网tx2@tx2:/media/mydisk/MyDocuments/PyProjects/automl/efficientdet$ curl https://bootstrap.pypa.io/get-pip.py | python3 - % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2108k 100 2108k 0 0 36367 0 0:00:59 0:00:59 --:--:-- 377k Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting pip Downloading pip-21.3-py3-none-any.whl (1.7 MB) |████████████████████████████████| 1.7 MB 9.5 kB/s Installing collected packages: pip WARNING: The scripts pip, pip3 and pip3.6 are installed in '/home/tx2/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pip-21.3
Q: pip警告
WARNING: pip is being invoked by an old script wrapper.
TypeError: expected str, bytes or os.PathLike object, not int(解决方法)
Python pip的安装及卸载
tx2@tx2:/media/mydisk/MyDocuments/PyProjects/automl/efficientdet$ pip --version WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly. pip 21.3 from /home/tx2/.local/lib/python3.6/site-packages/pip (python 3.6)
讯享网错误原因: setuptools和pip的版本不对应,所以升级一下pip就可以了 pip和python版本不匹配 解决办法: 方法一: 在pip指令前,添加 python3 -m 比如: python3 -m pip install numpy 查看pip版本以及安装路径 python3 -m pip --version pip 21.3 from /home/tx2/.local/lib/python3.6/site-packages/pip (python 3.6) 卸载pip python3 -m pip uninstall pip 卸载pip3 sudo apt-get remove python3-pip sudo apt autoremove 重装python2对应的pip curl https://bootstrap.pypa.io/get-pip.py | python - 或者 wget https://bootstrap.pypa.io/get-pip.py python get-pip.py 重装python3对应的pip3 curl https://bootstrap.pypa.io/get-pip.py | python3 - 或者 wget https://bootstrap.pypa.io/get-pip.py 修改 get-pip.py 第一行,修改为 #!/usr/bin/env python3 python3 get-pip.py 更新setuptools pip3 install --upgrade setuptools 升级pip python3 -m pip install -U pip 安装包 python -m pip 包名
tx2@tx2:/media/mydisk/MyDocuments/PyProjects/automl/efficientdet$ curl https://bootstrap.pypa.io/get-pip.py | python3 - % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2108k 100 2108k 0 0 381k 0 0:00:05 0:00:05 --:--:-- 494k Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting pip Downloading pip-21.3-py3-none-any.whl (1.7 MB) |████████████████████████████████| 1.7 MB 56 kB/s Installing collected packages: pip Successfully installed pip-21.3
Q: 更新pip错误
讯享网yoyo@yoyo:~/MyDocuments/PyProjects/Auto-Depth$ pip3 --version Traceback (most recent call last): File "/home/yoyo/.local/bin/pip3", line 7, in <module> from pip._internal.cli.main import main File "/home/yoyo/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57 sys.stderr.write(f"ERROR: {exc}") ^ SyntaxError: invalid syntax
错误原因: python版本与pip版本不匹配 博主当前python版本为3.5,更新pip版本为21.3.1,导致python版本与pip版本不匹配 Pip21.0.1版本在2020年1月停止支持Python2,在2020年3月停止支持Python3.5 方法一: 更新python版本
讯享网方法二: wget https://bootstrap.pypa.io/pip/3.5/get-pip.py 或者(如果上面的指令失败) wget https://bootstrap.pypa.io/3.5/get-pip.py python3 get-pip.py
Q:ERROR: This script does not work on Python 3.5 The minimum supported Python version is 3.6.
yoyo@yoyo:~/下载$ python3 get-pip.py ERROR: This script does not work on Python 3.5 The minimum supported Python version is 3.6. Please use https://bootstrap.pypa.io/pip/3.5/get-pip.py instead.
讯享网错误原因: python版本与pip版本不匹配 解决办法: 安装对应版本的pip wget https://bootstrap.pypa.io/pip/3.5/get-pip.py --no-check-certificate python3 get-pip.py --force-reinstall
Q: Defaulting to user installation because normal site-packages is not writeable
Defaulting to user installation because normal site-packages is not writeable
Q: pip镜像源地址错误
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Could not fetch URL https://mirrors.aliyun.com/pypi/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='mirrors.aliyun.com', port=443): Max retries exceeded with url: /pypi/simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
讯享网错误原因: pip镜像源地址错误 解决办法: https改为http sudo gedit ~/.pip/pip.conf [global] timeout = 6000 index-url = https://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com 改为 [global] timeout = 6000 index-url = http://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com
Q: pip安装找不到包
(pt2pb-tf114) PS F:\MyDocumentes\YOYOFile\Seeking\SeekingCode\deep_learn_frame-pyt-seg> pip install tensorflow==1.14 -i https://mirrors.aliyun.com/pypi/simple/ Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ ERROR: Could not find a version that satisfies the requirement tensorflow==1.14 (from versions: 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.6.0rc0, 2.6.0rc1, 2.6.0rc2, 2.6.0, 2.6.1, 2.6.2, 2.6.3, 2 .7.0rc0, 2.7.0rc1, 2.7.0, 2.7.1, 2.8.0rc0, 2.8.0rc1, 2.8.0, 2.9.0rc0, 2.9.0rc1) ERROR: No matching distribution found for tensorflow==1.14
讯享网错误原因: python3.9没有与之匹配的tensorflow版本。 博主当前的python版本是python3.9.12,支持tensorflow2.5+以上的版本。可以通过 https://mirrors.aliyun.com/pypi/simple/ 镜像网站查找python3.9所支持的 tensorflow 版本。 方法一: 降低python版本 方法二: 更换高版本的 <tensorflow
Q: GPG error 缺少公钥
W: GPG error: http://mirrors.ustc.edu.cn stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 648ACFD622F3D138 NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 605C66F00D6C9793 W: GPG error: http://mirrors.ustc.edu.cn stable-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 648ACFD622F3D138 NO_PUBKEY 0E98404D386FA1D9 The following signatures couldn‘t be verified because the public key is not available: NO_PUBKEY 问题 https://blog.csdn.net/uknow0904/article/details/
讯享网错误原因: 缺少公钥 解决办法: 按照报错提示,添加公钥 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <公钥>
Q:pip command not found
Linux pip command not found【已安装anaconda】
# 打开配置文件 vim ~/.bashrc # 添加配置 alias pip = '/home/user/anaconda3/bin/pip3' # 更新配置 source ~/.bashrc

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/80579.html