前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >配置 Python 环境 - Conda

配置 Python 环境 - Conda

原创
作者头像
1AI
发布2025-01-17 20:48:21
发布2025-01-17 20:48:21
2160
举报

这里推荐使用 Miniconda


下载安装 Miniconda

官方文档 - 下载 :https://docs.anaconda.com/miniconda/install/


方式一:下载安装包

安装包地址:https://www.anaconda.com/download/success

支持 Windows、macOS、Linux


macOS 在下载 pkg 安装包后,双击安装来安装;

安装成功后,将在终端 prompt 看到 (base) ,代表你进入了 base conda 环境。


你可以在终端输入下面命令来测试:

代码语言:shell
复制
conda list

方式二:使用脚本

Apple Silicon
代码语言:shell
复制
mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

Apple Intel
代码语言:shell
复制
mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

Linux 64-bit
代码语言:shell
复制
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

代码语言:shell
复制

安装低版本

你可以在这里找到低版本的 脚本、安装器

https://repo.anaconda.com/miniconda/


激活环境

安装成功后,运行下面命令来激活环境

代码语言:shell
复制
source ~/miniconda3/bin/activate

让 conda 在所有 shells 上有效,运行以下命令:

代码语言:shell
复制
conda init --all

conda 常用操作

环境管理


查看当下有哪些环境

代码语言:shell
复制
conda info -e

创建环境

基于 python 3.11

此处我命名环境名为 e311,你可以改为自己的名字

代码语言:shell
复制
conda create -n e311 python=3.11

复制环境

如果环境 e311 已经有一些很方便的包,但需要创建新环境,可以复制 e311

代码语言:shell
复制
conda create -n e3112 --clone e311

切换环境

代码语言:shell
复制
% conda info -e
# conda environments:
#
base                  *  /Users/shushu/miniconda3
e311                     /Users/shushu/miniconda3/envs/e311

(base) % conda activate e311

(e311) % conda activate base

退出环境

代码语言:shell
复制
conda deactivate

移除环境

代码语言:shell
复制
conda remove -n e311 --all

修改环境名

代码语言:shell
复制
conda create --name e11 --clone e311
conda remove --name e311 --all 

包管理

查看已经安装的package

代码语言:shell
复制
conda list

安装包

代码语言:shell
复制
conda install numpy 

安装指定版本

代码语言:shell
复制
conda install numpy==3.45.3

指定环境参数安装(-n)

代码语言:shell
复制
conda install -n e11 numpy

终端前显示了 环境名后,使用 pip install 也可以安装到当下环境


在源仓库查找包

代码语言:shell
复制
conda search sqlite

将返回历史版本信息

代码语言:shell
复制
 % conda search sqlite
Loading channels: done
# Name                       Version           Build  Channel             
sqlite                        3.20.1      h7e4c145_2  pkgs/main           
sqlite                        3.20.1      h900c3b0_1  pkgs/main           
sqlite                        3.21.0      h3efe00b_0  pkgs/main           
sqlite                        3.21.0      h3efe00b_2  pkgs/main           
...

更新包

代码语言:shell
复制
conda update numpy

卸载包

代码语言:shell
复制
conda remove numpy

其它命令:

代码语言:shell
复制
 % conda --help
usage: conda [-h] [-v] [--no-plugins] [-V] COMMAND ...

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

options:
  -h, --help          Show this help message and exit.
  -v, --verbose       Can be used multiple times. Once for detailed output, twice for INFO logging, thrice for DEBUG logging,
                      four times for TRACE logging.
  --no-plugins        Disable all plugins that are not built into conda.
  -V, --version       Show the conda version number and exit.

commands:
  The following built-in and plugins subcommands are available.

  COMMAND
    activate          Activate a conda environment.
    clean             Remove unused packages and caches.
    compare           Compare packages between conda environments.
    config            Modify configuration values in .condarc.
    content-trust     Signing and verification tools for Conda
    create            Create a new conda environment from a list of specified packages.
    deactivate        Deactivate the current active conda environment.
    doctor            Display a health report for your environment.
    env               See `conda env --help`.
    info              Display information about current conda install.
    init              Initialize conda for shell interaction.
    install           Install a list of packages into a specified conda environment.
    list              List installed packages in a conda environment.
    notices           Retrieve latest channel notifications.
    package           Create low-level conda packages. (EXPERIMENTAL)
    remove (uninstall)
                      Remove a list of packages from a specified conda environment.
    rename            Rename an existing environment.
    repoquery         Advanced search for repodata.
    run               Run an executable in a conda environment.
    search            Search for packages and display associated information using the MatchSpec format.
    update (upgrade)  Update conda packages to the latest compatible version.

伊织 2025-01-17(五)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 下载安装 Miniconda
    • 方式一:下载安装包
    • 方式二:使用脚本
      • Apple Silicon
      • Apple Intel
      • Linux 64-bit
      • 安装低版本
      • 激活环境
  • conda 常用操作
    • 环境管理
    • 包管理
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档