Wheel 安装包

http://www.lfd.uci.edu/~gohlke/pythonlibs/

Conda

开始

conda info:查看系统相关信息
conda list:查看已安装的库
conda --help:罗列帮助
conda -h:同上[1]
conda <param_name> --help:获取<param_name>帮助
conda --versionconda -V

安装及更新

安装库:

  1. $ conda install <moudule_name>

特别注意,升级本机或者虚拟环境的 Python 版本可以用如下命令(当前 Python 版本为 3.7):

  1. $ conda install -c anaconda python=3.8

可在 官方源 中查看 Anaconda 官方支持的最新 Python 版本。若官方源没有更新,可查看 conda-forge 源的更新。若有更新,执行如下命令:

  1. $ conda install -c conda-forge python

更新库:

  1. $ conda update <module_name>

更新conda自身,用命令 conda update conda

环境管理

envs/sonwflaskes创建一个新的环境,新建程序Biopython

  1. conda create --name sonwflakes biopython

默认安装在envs路径中,可用conda info --envs命令查看

创建第二个环境

  1. conda create --name bunnies python=3 astroid babel

在路径envs/bunnies路径下创建新的环境,同时安装不同版本的Python及Astroid、Babel两个包。

列举所有的环境:conda info --envs
:当前环境前会有*号标注。

环境切换
Linux, OS X: source activate bunnies
Windows: activate bunnies

克隆一个环境
克隆snowflaskes,新环境命名为flowers:

  1. conda create --name flowers --clone snowflakes

删除环境

  1. conda remove --name flowers --all

管理Python

检查Python版本

  1. conda search python

安装不同Python版本的虚拟环境

  1. conda create --name snakes python=3

包管理

列举包:

  1. $ conda list

查找包:

  1. $ conda search beautiful-soup

安装包:

  1. $ conda install --channel https://conda.anaconda.org/pandas bottleneck

安装商业的包:

  1. $ conda install matplotlib<=1.2>

requirements.txt 文件中安装:

  1. $ conda install --yes --file requirements.txt

移除包:

  1. conda remove --name bunnie iopro

移除一个环境:

  1. conda remove --name snakes --all

移除 conda

  • Linux, OS X:rm -rf ~/minicondarm -rf ~/anaconda
  • Windows:直接卸载

初始化

初始化 conda,使得 shell 默认激活一个 Python 环境:

  1. $ conda init

Linux 环境下,安装完成后是相关环境变量添加到了 ~/.bashrc ,若使用的是 zsh 环境,则 conda 相关命令无效,这时候需要将相关环境变量添加到 ~/.zshrc 中,也可以运行如下命令自动完成添加:

  1. $ conda init zsh

其他

  1. $ conda package
  2. $ conda index

镜像

新增编辑文件 ~/.condarc

  1. channels:
  2. - defaults
  3. show_channel_urls: true
  4. default_channels:
  5. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  6. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  7. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  8. custom_channels:
  9. conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  10. msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  11. bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  12. menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  13. pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  14. simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

虚拟环境

安装 32 位的 Python

如果系统是64位版本的Python,但是同时需要32位版本的话,可以在创建虚拟环境之前,添加环境变量:

  1. set CONDA_FORCE_32BIT=1

然后正常执行创建虚拟环境命令,即可创建一个32位版本的 Python 环境。

Cheat sheet

小抄: conda cheat sheet
conda-cheatsheet.pdf

资源

pip

更新

  • Linux or OS X: pip install -U pip
  • Windows:python -m pip install -U pip

包管理

安装升级

  1. $ pip install SomePackage # latest version
  2. $ pip install SomePackage==1.0.4 # specific version
  3. $ pip install 'SomePackage>=1.0,<=2.0' # scope version
  4. $ pip install SomePackage -U

卸载

  1. $ pip uninstall SomePackage

查看

  • pip search <module_name>:查找库
  • pip show <module_name>:查看库信息
  • pip list:查看已经安装的库
  • pip list --outdated:获取过期的库
  • pip list --outdated | grep Jinja2

镜像

  1. $ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

pipx

  1. python -m pip install --user pipx
  2. python -m pipx ensurepath
  3. pipx completions

使得环境变量生效:

  1. # for bash
  2. source ~/.bashrc
  3. # for zsh
  4. source ~/.zshrc

poetry

  1. pipx install poetry
  2. pipx upgrade poetry
  3. pipx uninstall poetry

Pipenv

一年多没发新版了,速度等问题没有解决,弃之!
Python 依赖包管理工具,整合 pip、virtualenv 等包管理库,类似于 node.js 的 npm,提供易用的依赖包管理功能。
一个典型的 Pipfile 文件如下:

  1. [[source]]
  2. url = "https://pypi.org/simple"
  3. verify_ssl = true
  4. name = "pypi"
  5. [packages]
  6. django = "*"
  7. [dev-packages]
  8. yapf = "*"
  9. [scripts]
  10. server = "python manage.py runserver"
  11. [requires]
  12. python_version = "3.7"

此文件是一个 toml 格式的文件。

参考: