安装 anaconda



下载

到官方网站找到需要的安装包
https://www.anaconda.com/products/distribution

在 Ubuntu 用的是

curl -O https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh

文件 600 多 M 下载速度可能比较慢,可以用迅雷等工具下载

官网显示这个包支持 Python3.9 但这不会影响我们创建其他版本比如 Python3.6 的环境

安装

sh Anaconda3-2022.05-Linux-x86_64.sh

安装的最后一步会问要不要 init,意思是每次启动 shell 都会进入 anaconda 的 base 环境

(base) lin@lin-VirtualBox:~$ 

如果设置了,后面又不希望默认进入 base,可以改 .bashrc 文件

换源

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

换后可以查看信息

创建自己的环境

conda create -n py3 python=3.6    ## py3 是环境名,任意名字都可以

如果创建的时候遇到错误

NoWritableEnvsDirError: No writeable envs directories configured.

那可能是权限问题需要调整

chmod 777 /home/lin/.conda

查看环境

lin@lin-VirtualBox:~$ conda info -e
# conda environments:
#
py3                      /home/lin/.conda/envs/py3
base                  *  /home/lin/anaconda3

进入环境

conda activate py3

退出环境

conda deactivate

可以修改 .bashrc 决定在启动 shell 的时候要不要进入默认环境

在环境里安装自己需要的包

conda install -c anaconda tensorflow
conda install pytorch torchvision cpuonly -c pytorch
conda install seaborn
conda install pyod
conda install tsod

# tensorflow 2.0 集成了 keras,这样不用再单独装 keras
pip install tensorflow==2.0.0
pip install tensorflow_hub
pip install tensorflow_datasets
pip install combo
pip install ruptures

conda list

如果 conda install 报错

Collecting package metadata (current_repodata.json): failed

下面更具体的错误为

conda.core.subdir_data.Response304ContentUnchanged

那么可以尝试清理 cache 后重装

conda clean -i

重装就没问题了

如果遇到错误

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

有可能是 anaconda 版本低,需要升级

启动 jupyter

anaconda 自带 jupyter

到某个用于存 ipynb 文件的目录下,启动 jupyter

jupyter notebook

到浏览器打开 http://localhost:8888/

但这个命令可能不会用到自己创建的 conda 环境下的 Python

要用特定 conda 环境下的 Python,可以这样

conda activate py3

pip install jupyter

python -m jupyter notebook

这样 jupyer 用的就是 py3 环境下的 python



posted @ 2022-09-01 23:48  moon~light  阅读(346)  评论(0编辑  收藏  举报