天天看點

pip 與 conda 指令pip與conda

pip與conda

CSDN - anaconda,conda,pip的關系

新浪部落格 - Anaconda、Miniconda、Conda、pip的互相關系

使用上的了解:

  1. conda 安裝包的時候會将預設依賴的很多包一起安裝,如果之前沒有這些包就下載下傳,有但版本不合适就更新,如果已安裝的包不相容會将這些包解除安裝。當安裝前會提示是否确認,是以要仔細看下小心卸掉已有的包或者将已有的包降低版本。

    pip 安裝的時候依賴項相對于 conda 來說要少很多,隻會安裝必需的包,可能是以會産生版本不相容問題,但不會對原有環境做太多變更。

  2. pip 是 python 官方庫,包含的 python 包的範圍要比 conda 大。

pip : python installer for python

pip -V / --version : 檢視pip版本

pip list : 列出所有包

pip show package_name : 查找已安裝包的資訊

pip search package_name : 搜尋 PyPI(Python Package Index) 的包

pip install package_name[==version] : 安裝指定的包

pip / pip help / pip -h / pip --help :

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

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
           

conda

conda -V / --version : 檢視conda版本

conda list : 列出所有包

conda list package_name : 查找已安裝包的資訊

conda search package_name : 搜尋PyPI(Python Package Index)的包

conda install package_name[==version] : 安裝指定的包

conda update package_name[==version] : 更新包

conda info -e / --envs || conda env list : 列出所有conda環境

conda create -n env_name package_name[=version] : 建立新環境

conda create -n env_name_new --clone env_name_old : 克隆環境

conda activate env_name : 使用此環境

conda deactivate : 退出此環境

conda remove -n env_name --all : 删除指定環境

conda clean -p : 删除沒有用的包,這個指令會檢查哪些包沒有在包緩存中被硬依賴到其他地方,并删除它們

conda clean -t : tar打包,通過conda clean -t可以将conda儲存下來的tar包

conda clean -y -all : 删除所有的安裝包及cache

添加鏡像:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
           

顯示配置:

conda config --show
conda config --show-sources
           

移除鏡像:

conda config --remove channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/' 
           

conda / conda help / conda -h / conda --help :

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

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

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    config       Modify configuration values in .condarc. This is modeled after the git config command. Writes to the user .condarc file (C:\Users\Administrator\.condarc) by default.
    create       Create a new conda environment from a list of specified packages.
    help         Displays a list of available conda commands and their help strings.
    info         Display information about current conda install.
    init         Initialize conda for shell interaction. [Experimental]
    install      Installs a list of packages into a specified conda environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove.
    run          Run an executable in a conda environment. [Experimental]
    search       Search for packages and display associated information. The input is a MatchSpec, a query language for conda packages. See examples below.
    update       Updates conda packages to the latest compatible version.
    upgrade      Alias for conda update.

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
  debug
  develop
  env
  index
  inspect
  metapackage
  render
  server
  skeleton
  verify
           

conda info -h / --help :

usage: conda-script.py info [-h] [--json] [-v] [-q] [-a] [--base] [-e] [-s] [--unsafe-channels]

Display information about current conda install.

Options:

optional arguments:
  -h, --help         Show this help message and exit.
  -a, --all          Show all information.
  --base             Display base environment path.
  -e, --envs         List all known conda environments.
  -s, --system       List environment variables.
  --unsafe-channels  Display list of channels with tokens exposed.

Output, Prompt, and Flow Control Options:
  --json             Report all output as json. Suitable for using conda programmatically.
  -v, --verbose      Use once for info, twice for debug, three times for trace.
  -q, --quiet        Do not display progress bar.
           

conda create -h / --help :

usage: conda-script.py create [-h] [--clone ENV] [-n ENVIRONMENT | -p PATH]
                              [-c CHANNEL] [--use-local] [--override-channels]
                              [--strict-channel-priority]
                              [--no-channel-priority]
                              [--no-deps | --only-deps] [--no-pin] [--copy]
                              [--no-shortcuts] [-C] [-k] [--offline] [-d]
                              [--json] [-q] [-v] [-y] [--download-only]
                              [--show-channel-urls] [--file FILE]
                              [--no-default-packages]
                              [package_spec [package_spec ...]]

Create a new conda environment from a list of specified packages. To use the cre
ated environment, use 'source activate envname' look in that directory first.  T
his command requires either the -n NAME or -p PREFIX option.

Options:

positional arguments:
  package_spec          Packages to install or update in the conda environment.

optional arguments:
  -h, --help            Show this help message and exit.
  --clone ENV           Path to (or name of) existing local environment.
  --file FILE           Read package versions from the given file. Repeated file specifications can be passed (e.g. --file=file1 --file=file2).

Target Environment Specification:
  -n ENVIRONMENT, --name ENVIRONMENT Name of environment.
  -p PATH, --prefix PATH Full path to environment location (i.e. prefix).

Channel Customization:
  -c CHANNEL, --channel CHANNEL
                        Additional channel to search for packages. These are URLs searched in the order they are given (including
                        file:// for local directories). Then, the defaults or channels from .condarc are searched (unless
                        --override-channels is given). You can use 'defaults' to get the default packages for conda. You can also
                        use any name and the .condarc channel_alias value will be prepended. The default channel_alias is
                        http://conda.anaconda.org/.
  --use-local           Use locally built packages. Identical to '-c local'.
  --override-channels   Do not search default or .condarc channels. Requires
                        --channel.

Solver Mode Modifiers:
  --strict-channel-priority
                        Packages in lower priority channels are not considered if a package with the same name appears in a higher priority channel.
  --no-channel-priority
                        Package version takes precedence over channel priority. Overrides the value given by `conda config --show channel_priority`.
  --no-deps             Do not install, update, remove, or change dependencies. This WILL lead to broken environments and inconsistent behavior. Use at your own risk.
  --only-deps           Only install dependencies.
  --no-pin              Ignore pinned file.
  --no-default-packages Ignore create_default_packages in the .condarc file.

Package Linking and Install-time Options:
  --copy                Install all packages using copies instead of hard- or soft-linking.
  --no-shortcuts        Don't install start menu shortcuts

Networking Options:
  -C, --use-index-cache Use cache of channel index files, even if it has expired.
  -k, --insecure        Allow conda to perform "insecure" SSL connections and transfers. Equivalent to setting 'ssl_verify' to 'false'.
  --offline             Offline mode. Don't connect to the Internet.

Output, Prompt, and Flow Control Options:
  -d, --dry-run         Only display what would have been done.
  --json                Report all output as json. Suitable for using conda programmatically.
  -q, --quiet           Do not display progress bar.
  -v, --verbose         Can be used multiple times. Once for INFO, twice for DEBUG, three times for TRACE.
  -y, --yes             Do not ask for confirmation.
  --download-only       Solve an environment and ensure package caches are populated, but exit prior to unlinking and linking packages into the prefix.
  --show-channel-urls   Show channel urls. Overrides the value given by `conda config --show show_channel_urls`.

Examples:

    conda create -n myenv sqlite