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 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
nvidia-smi
—>CUDA 10.1
以向下兼容为准
CUDAToolkit
与PyTorch
版本对应:具体方法
Python
与PyTorch
,torchvision
版本对应:具体方法
torchtext
与PyTorch
, Python
版本对应:具体方法
## 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()
注意| 安装中出现的问题
No module named ‘torchtext.legacy’
jupyter安装?没必要
cuda
cuda
添加清华源镜像
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 config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
bug
# DGL
https://docs.dgl.ai/guide_cn/index.html
conda install -c dglteam dgl
# Hydra
https://hydra.cc/docs/intro/
pip install —upgrade pip
pip install hydra-core
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:
具体方法
# 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↓
三种帮助:dir(Dataset), help(Dataset), Dataset??
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安装教程
教程
tensorboard
Move the mouse to the directory where the log file is located, right-click and select
open in terminal
.
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
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-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