python安装、卸载包的方法

1 anaconda包管理器

2 conda命令[1]

  • 环境管理

    conda info -e              # 查看当前已安装的环境
    conda create -n py27 python=2.7   # 添加2.7版本的Python环境
    activate py27               # 切换到Python2.7环境
    deactivate                 # 返回默认的Python环境
    conda remove -n py27 --all      # 删除已安装的Python环境
    
  • 包管理

    conda list               # 查看当前环境下已安装的包
    conda list -n py27          # 查看指定环境的已安装的包
    conda search pandas        # 查找package信息
    conda install -n py27 pandas  # 指定环境安装package,不加-n则安装在当前活跃环境
    conda update -n py27 pandas   # 指定环境更新package,不加-n则更新在当前活跃环境
    conda remove -n py27 pandas   # 删除package,不加-n则删除在当前活跃环境
    
  • 更新Python和conda版本

    conda update conda   # 更新conda
    conda update anaconda  # 更新anaconda
    conda update python   # 更新python,假设当前环境是3.6,则更新3.6.x系列版本
    

3 pip命令

3.1 安装pip组件 [2]

sudo apt-get install python3-pip # 安装pip3
sudo apt-get install python-pip # 安装pip2
sudo pip3 install --upgrade pip # 更新pip
sudo apt-get remove python3-pip # 卸载pip

3.2 pip镜像源配置[3]

3.2.1 临时使用国内源

# 以清华源为例
# xxx为所要安装的包
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx
pip install xxx -i https://pypi.tuna.tsinghua.edu.cn/simple 

3.2.2 配置国内源为默认使用

  • 配置国内源为默认使用(windows)

    • 建立C:\Users\xxx(用户名)\pip\pip.ini文件

    • 添加如下命令(阿里云为例)

[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
  • 配置国内源为默认使用(linux)

    • # 编辑 ~/.pip/pip.conf 文件,若不存在自行创建即可

    • vim ~/.pip/pip.conf

[global]
timeout = 8
index-url =  http://mirrors.aliyun.com/pypi/simple/
extra-index-url= http://pypi.douban.com/simple/
[install]
trusted-host=
mirrors.aliyun.com
pypi.douban.com
  • 国内常用的pip镜像源

    清华镜像:https://pypi.tuna.tsinghua.edu.cn/simple
    豆瓣镜像:http://pypi.douban.com/simple
    阿里云: http://mirrors.aliyun.com/pypi/simple/
    
  • 问题:对于多个环境的pip怎么设置?

3.3 pip包安装命令[4]

  ```bash
  pip install package_name           # 安装包
  pip install whl文件                # 安装下载好的whl文件包 
  pip uninsatll package_name         # 卸载包
  pip list 						   # 列出pip所安装的包
  pip install --upgrade package_name # 升级包
  pip --help                         # 帮助信息
  pip show -f pandas                 # 显示pandas包所在的目录
  pip search pandas                  # 搜索pandas包
  ```

4 easy_pip命令

参考资料:


  1. https://www.jb51.net/article/164669.htm ↩︎

  2. https://blog.csdn.net/qintaiwu/article/details/89393028 ↩︎

  3. https://blog.csdn.net/wj1066/article/details/81940163 ↩︎

  4. https://www.cnblogs.com/xueweihan/p/4981704.html ↩︎

posted @ 2021-06-10 00:18  smileGIS  阅读(6420)  评论(0编辑  收藏  举报