JyLie

vuePress-theme-reco JyLie    2017 - 2023
JyLie

Choose mode

  • dark
  • auto
  • light
主页
分类
  • API
  • HTML
  • css
  • vue
  • Linux
  • Docker
  • Webpack
  • WebGL
  • PixiJS
  • Github
  • BOM
  • XML
  • bug
  • ie
  • uniapp
  • IE
  • mysql
  • font
  • bom
  • canvas
  • video
  • html
  • JavaScript
  • js
  • 运算符
  • RegExp
  • 编码
  • MiniApp
  • nginx
  • Tool
  • node.js
  • cat
  • nodejs
  • protocol
  • URL
  • FLOW
  • DNS
  • Protocol
  • python
  • 安全
  • linux
  • shell
  • IDE
  • Packer
  • ViteJS
  • git
  • vendor
  • WebApp
  • WebView
  • Window API
  • webview
  • 规范
标签
时光轴
GitHub
author-avatar

JyLie

74

Article

79

Tag

主页
分类
  • API
  • HTML
  • css
  • vue
  • Linux
  • Docker
  • Webpack
  • WebGL
  • PixiJS
  • Github
  • BOM
  • XML
  • bug
  • ie
  • uniapp
  • IE
  • mysql
  • font
  • bom
  • canvas
  • video
  • html
  • JavaScript
  • js
  • 运算符
  • RegExp
  • 编码
  • MiniApp
  • nginx
  • Tool
  • node.js
  • cat
  • nodejs
  • protocol
  • URL
  • FLOW
  • DNS
  • Protocol
  • python
  • 安全
  • linux
  • shell
  • IDE
  • Packer
  • ViteJS
  • git
  • vendor
  • WebApp
  • WebView
  • Window API
  • webview
  • 规范
标签
时光轴
GitHub
  • pip包管理工具基本使用

    • 安装
      • 配置 pip 源镜像
        • 国内源地址:
          • 更改默认下载路径
            • 基本操作
              • debug

              pip包管理工具基本使用

              vuePress-theme-reco JyLie    2017 - 2023

              pip包管理工具基本使用


              JyLie 2020-02-09 python tool

              # pip 包管理工具 基本使用

              pip 是一款 python 包管理工具

              # 安装

              wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
              
              python3 get-pip.py
              
              # 将pip3加入环境变量
              
              vi /etc/profile
              
              export PATH=$PATH:/usr/local/bin
              
              #重新加载环境变量文件
              
              source /etc/profile
              
              1
              2
              3
              4
              5
              6
              7
              8
              9
              10
              11
              12
              13

              # 配置 pip 源镜像

              # 国内源地址:

              • 阿里云 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/
              • 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
              # mac
              vi .pip/pip.conf # 打开配置文件
              # 插入以下内容, 即可切换为豆瓣源
              [global]
              trusted-host=pypi.douban.com
              index-url=http://pypi.douban.com/simple
              
              # windows在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下
              [global]
              index-url = https://pypi.tuna.tsinghua.edu.cn/simple
              [install]
              trusted-host = https://pypi.tuna.tsinghua.edu.cn
              
              
              1
              2
              3
              4
              5
              6
              7
              8
              9
              10
              11
              12
              13

              # 更改默认下载路径

              • 查看 pip 下载包的默认路径
              python3 -m sitepython -m site -help
              
              1

              显示以下内容:

              PS F:\Github\tool-library\python\test> python3 -m site
              sys.path = [
                  'C:\\Python38-32\\python38.zip',
                  'C:\\Python38-32\\DLLs',
                  'C:\\Python38-32\\lib',
                  'C:\\Python38-32',
                  'C:\\Python38-32\\lib\\site-packages',
              ]
              USER_BASE: 'C:\\Users\\Administrator\\AppData\\Roaming\\Python' (doesn't exist)
              USER_SITE: 'C:\\Users\\Administrator\\AppData\\Roaming\\Python\\Python38\\site-packages' (doesn't exist)
              ENABLE_USER_SITE: True
              
              1
              2
              3
              4
              5
              6
              7
              8
              9
              10
              11

              可以看到你的 python 安装目录

              USER_SITE:自定义 Python 依赖安装包的基础路径。

              USER_BASE:自定义 Python 脚本

              然后查看 site.py 所在目录

              python -m site -help
              
              1

              找到目录修改对应的路径,建议将路径设置在 python 目录关联的位置较好

              # 基本操作

              • 安装包
              pip3 install requests # 默认安装最先版包
              pip3 install requests==1.1.0 # 安装指定版本包
              
              1
              2
              • 批量安装包
              pip install -r requirements.txt
              
              1

              其中 requirements.txt 文件格式

              Werkzeug==0.9.4
              psycopg2==2.5.1
              
              1
              2
              • 卸载包
              pip3 uninstall requests
              
              1
              • 更新某个包
              pip3 install -U requests
              # 或
              pip3 install --upgrade requests
              
              1
              2
              3
              • 查看已安装的所有包
              pip3 list
              
              
              1
              2
              • 显示包文件
              pip show --files requests
              
              1
              • 指定安装路径
              pip install requests --target=/Users/Python/2.7/lib/python/site-packages
              
              1
              • 安装某个包时指定源
              pip3 install requests -i http://pypi.douban.com/simple
              
              1
              • 安装离线包
              # 离线包下载地址 https://www.lfd.uci.edu/~gohlke/pythonlibs/
              pip3 install xxxxxxx.whl # 安装
              
              1
              2
              • 查看系统支持的安装包
              python3 -c "import pip._internal;print(pip._internal.pep425tags.get_supported())"
              
              1

              # debug

              • 安装离线包, 报错: xxx.whl is not a supported wheel on this platform

              解决: 下载系统所支持的离线包即可

              
              
              1