anaconda 配置

安装 | anaconda

linux 服务器下安装 anaconda,使用工具 Xshell+WinSCP
具体方法
【注意】配置~/.bashrc 文件

# 未配置下输入conda出现错误 → conda: command not found

# 1. 在 .bashrc 文件最后一行加上
export PATH="/data0/lizhong/anaconda3/bin:$PATH"  # 可以通过 echo $PATH 查看结果
# 2. 或者命令行输入
echo 'export PATH="/data2/lizhong/anaconda3/envs/mytorch/bin:$PATH"'>> ~/.bashrc

# 激活
source .bashrc

which python  # 查看系统调用那个位置的Python
import sys
sys.path # 查看正在使用的python是哪个位置的python

conda list  # 显示已经安装的包名和版本号
conda search -f transformers  # 查询可用版本的安装包
conda env list  # View all created virtual environments  
conda info -e   # same operation 
conda create -n  mytorch python=3.9  # create new virtual environment

conda activate mytorch  # activate the virtual environment
conda deactivate  # exit the virtual environment

conda remove -n mytorch --all  # delete virtual environment

添加 | 清华源

【注意】是 http ,不是 https

conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/clound/pytorch

# 从 channel 中安装包时显示 channel 的 url, 方便查看包的安装来源(如下图)
conda config --set show_channel_urls yes

创建 | 虚拟环境 env

显卡驱动版本、cudatoolkit版本、cudann版本、tensorflow-gpu版本之间的对应关系
nvidia-smi —>CUDA 10.1 以向下兼容为准

## cuda 10.4/10.1
conda create -n mytorch python=3.6
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch
pip install torchtext==0.8.1

## cuda 11.7
# conda create -n mytorch python=3.9    
# conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch  # 去掉 -c pytorch 否则从官方下载,而不是从清华源下载
# pip install torchtext==0.13.1

 # install others 
conda install ipython
conda install jupyter

import torch
torch.__version__
torch.version.cuda
torch.cuda.is_available()
torch.backends.cudnn.version()

【注意】 安装中可能出现的问题:
No module named ‘torchtext.legacy’
jupyter安装?没必要
cuda
cuda

jupyter虚拟环境配置

安装 | 其他包

bug

1. DGL

官网
博客
博客
dgl教程
Run pip install dgl-cu101==0.6.1 安装

2. Hydra and Omegaon
# Hydra
https://hydra.cc/docs/intro/
pip install —upgrade pip
pip install hydra-core
3. Apex
python=3.6
# CUDA 11.0
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

# 法一
git clone https://github.com/NVIDIA/apex
或 git clone git://github.com/NVIDIA/apex

cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

出现错误:改为 pip install -v --no-cache-dir ./


# 法二  先直接在github下载apex包,上传到服务器上
unzip apex-master.zip
cd apex-master
python setup.py install  # Python安装  可能需要pip install packaging

或者 python setup.py install --cpp_ext --cuda_ext

错误并没有消失原因:之后再说

Cuda extensions are being compiled with a version of Cuda that does not match the version used to compile Pytorch binaries.  Pytorch binaries were compiled with Cuda 11.0.

Compiling cuda extensions with
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2019 NVIDIA Corporation
    Built on Sun_Jul_28_19:07:16_PDT_2019
    Cuda compilation tools, release 10.1, V10.1.243
    from /usr/local/cuda/bin

a minor-version mismatch will not cause later errors:

安装 jupyter notebook

具体方法

# install by conda(Not recommended, always bugs)
conda install ipython
conda install jupyter

# install by pip or pip3(recommended)
python -m pip install --upgrade up pip  # upgrade pip tool
pip3 install --upgrade pip  # Upgrade to the latest version
pip3 install jupyter
pip list  # View all installed packages
conda list # same command

在 Anaconda Prompt 终端中键入:jupyter notebook,浏览器会自动启动 Jupyter Notebook,浏览器地址栏中默认地址会显示:http://localhost:8888

jupyter notebook 的两种不同键盘输入模式:

  • 编辑模式: 允许您将代码或文本输入到一个单元格(cell)中,单元格显示绿色边框。
    切换方式:单击单元格内,或者直接按键盘上 Enter 键,即可进入编辑模式。
  • 命令模式: 键盘与notebook命令绑定在一起,单元格显示蓝色边框。
    切换方式:单击单元格外任何位置,或者直接按键盘上 Esc 键,即可进入命令模式。

Call up jupyter notebook shortcuts↓

  • Method 1:在命令模式下,按键盘上 h 键。
  • Method 2:在界面“Help”菜单下,点击“Keyboard Shortcuts”

三种帮助:dir(Dataset), help(Dataset), Dataset??

5. Install tensorflow

conda create -n tensorflow python=3.6  # create a virtual environment named tensorflow
conda activate tensorflow  # enter the virtual environment

pip install tensorflow==1.9.0  # install specified version of tensorflow
pip uninstall tensorflow==1.9.0  # uninstall specified version of tensorflow
pip install --upgrade tensorflow-gpu  # upgrade tensorflow to  latest GPU version
pip install --upgrade tensorflow  # upgrade tensorflow to latest CPU version

# install pytorch in this virtual environment,Note the version.
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cpuonly 

# install scipy
pip install --index-url https://pypi.douban.com/simple scipy==1.0.0

python
>> import tensorflow as tf
>> tf.__version__  # View the current version of tensorflow
>> tf.__path__  # View the current installation path of tensorflow
>> import torch
>> torch.__version__
>> import torchvision
>> torchvision.__version__

【Elink】
python与TensorFlow版本对应,不同版本不兼容
Win10 + Anaconda + Tensorflow-cpu + Pycharm安装教程

教程

6. start up tensorboard

6.1 in pycharm

  • open in terminal

Move the mouse to the directory where the log file is located, right-click and select open in terminal.

  • Start up tensorboard

type in the terminal↓

tensorboard --logdir "path of logs" --port=8008

You alseo can Specify GPU↓

CUDA_VISIBLE_DEVICES=id tensorboard --logdir "path of logs" --host=127.0.0.1 --port=8008

  • Click the URL

If it is not opened successfully on the browser, check whether the port is already occupied.

【E.g】win+R>>CMD>>type netstat -ano | findstr "8008"
【E.g】http://localhost:8008/

Anaconda installer(Mac)

anaconda-navigator  # Anaconda Navigator的图形界面将会被启动

设置环境

  • 修改~/.zshrc~/.bash_profile文件
# 在 ~/.zshrc 文件中添加 export PATH="/Users/yourname/opt/anaconda3/bin:$PATH"
# source ~/.zshrc
  • 修改~/.condarc文件
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

【注】source .condarc出现的问题:交换文件 “.conadrc.swp” 已存在!
恢复文件 rm -f .condarc.swp

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值