Python包管理

安装包时,尽量不要在不必要的时候指定包的版本,否则可能造成不兼容而使python无法正常运行。

Anaconda介绍

基本操作

  • conda update --help:在对应命令后面添加 --help 可以获得对应命令的帮组文档
  • conda --version:查看对应 conda 和 python 的帮组文档
  • conda update conda:更新指定包,更新所有 --all
  • conda create --name tensorflow python=3.6 tensorflow:创建指定python版本的环境(不指定python版本将与conda版本一致的python版本),并安装指定包
  • conda create --name tensorflow-clone --clone tensorflow:复制 tensorflow 环境创建一个 tensorflow-clone 环境
  • (source) activate tensorflow:(Linux或OS X)Windows 启动指定环境;默认启动默认创建的 base 环境
  • deactivate:停用当前活动环境
  • conda info --envs:获取当前所有的环境;当前活动环境在命令行开头通过 (tensorflow)和查看时活动环境前加 * 指示
  • conda remove --name tensorflow --all:删除指定环境
  • conda remove --name tensorflow tensorflow:删除指定环境中的指定包
  • conda search --full-name tensorflow:搜索指定包
  • conda list:列举出当前环境安装的所有包
  • conda intall tensorflow:安装指定包,可以通过 --name tensorflow 指定安装环境。对于没有的包,可以在 anaconda.org 上查找安装方式。
  • conda install --channel https://conda.anaconda.org/pandas bottleneck:从Anaconda.org下载并安装指定包
  • conda install -c conda-forge package_name:从 Anaconda.org 上下载的包一般采用如下方式安装。需要注意的是下载的时候注意运行平台,如果平台不对可能造成无法运行。
  • pip install tensorflow:安装 pip 中的指定包
  • conda config:配置conda(修改用户路径下的 .condarc文件),比如添加channel

官方文档

usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packaes.

Options:
positional arguments:
  command
    clean             移除未被使用的包和缓存.
    config           修改 .condarc 中的配置值. 这是在 git config 命令后建模的. 
    create           创建一个新的 conda 环境,并安装后续指定的包.
    help              显示可用的 conda 命令和帮组文档.
    info               显示当前 conda 安装的信息.
    install            向指定的 conda 环境安装指定的包.
    list                 列出一个 conda 环境中链接的包.
    package        低阶 conda 包实用程序. (EXPERIMENTAL)
    remove          从指定环境中移除指定包.
    uninstall         conda remove 的别名. 参考 conda remove --help.
    search            查找包并显示相关信息. 支持模糊查询
    update           将 conda 包更新到最新的兼容版本. 可以使用  --no-update-deps option 避免更新已安装的包. 也可以使用 --force 跳过依赖性检查.
    upgrade         conda update 的别名. 参考 conda update --help.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.

conda commands available from other packages:
  build
  convert
  develop
  env
  index
  inspect
  metapackage
  render
  server
  skeleton
  verify

Pip命令介绍

更新 pip 的命令:python -m pip install --upgrade pip

Usage:

  pip <command> [options]

Commands:

  install                  安装包.
  download           下载包.
  uninstall              卸载包.
  freeze                  按着一定的格式输出已安装包列表.
  list                        列出已安装包.
  show                    显示包详细信息.
  check                   验证安装包具有完整的依赖.
  config                  管理本地和全局配置.
  search                  在PyPI中搜索包.
  wheel                   根据需要构建wheels.
  hash                     计算包归档的哈希值.
  completion          用于命令完成的辅助命令.
  help                      显示命令的帮组文档.

General Options:

  • -h, --help           Show help.
  • --isolated           Run pip in an isolated mode, ignoring environment variables and user configuration.
  • -v, --verbose      Give more output. Option is additive, and can be used up to 3 times.
  • -V, --version       Show version and exit.
  • -q, --quiet          Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  • --log <path> Path to a verbose appending log.
  • --proxy <proxy>          Specify a proxy in the form [user:passwd@]proxy.server:port.
  • --retries <retries>        Maximum number of retries each connection should attempt (default 5 times).
  • --timeout <sec>           Set the socket timeout (default 15 seconds).
  • --exists-action <action>       Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  • --trusted-host <hostname>  Mark this host as trusted, even though it does not have valid or any HTTPS.
  • --cert <path>                         Path to alternate CA bundle.
  • --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  • --cache-dir <dir>             Store the cache data in <dir>.
  • --no-cache-dir                  Disable the cache.
  • --disable-pip-version-check   Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
  • --no-color                               Suppress colored output

虚拟环境(Virtualenv)

参考博文:https://blog.csdn.net/watermusicyes/article/details/72909752

虚拟环境提供了在一台服务器上运行需要不同python运行环境的多个程序,创造出独立的python运行环境。

可以使用 conda 也可以使用 pip 安装虚拟环境

pip 方式

  • 安装 virtualenv:pip install virtualenv
  • 可以使用 virtualenv [准备创建虚拟环境的路径] 来创建一个python 虚拟环境,也可以通过 python -m -venv [准备创建虚拟环境的路径]
  • 可以通过 -p 参数来制定使用的 python 环境,virtualenv -p /usr/local/bin/python3 venv
  • virtualenv --no-site-packages [虚拟环境名称],创建一个纯净的 python 环境

启动方式:source [虚拟环境名称]/bin/activate,终止方式:deactivate

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值