Anaconda-Python环境安装

查询版本信息

  • 驱动器版本:右键NVIDIA–>系统信息(点击开始菜单,搜索dxdiag

安装Anaconda

下载网址:https://repo.anaconda.com/archive/
安装事项

  1. 修改路径

  2. 不要勾选“Add Anaconda to the system PATH environment variable”。

  3. 添加上:Anaconda3、Anaconda3/Scripts、Anaconda3/Library/bin这3个文件夹的路径(用户+系统的Path,环境变量打开方式为:计算机–属性–高级系统设置–环境变量)

设置镜像源

清华镜像网址:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

参考:https://www.cpci.dev/anaconda-mirrors-configure/

  1. 生成 .condarc 文件: conda config --set show_channel_urls yes(C:\users\username\)

  2. 清华源复制到 .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
    ssl_verify: false
    # 命令行
    conda clean -i
  3. 不走镜像、代理设置

    channels:
    - defaults
    show_channel_urls: true
    proxy_servers:
    http: 127.0.0.1:7890
    https: 127.0.0.1:7890
    ssl_verify: false

conda安装tensorflow

conda create -n tf python=3.6
activate tf
conda install tensorflow-gpu=1.9.0
# 根据python版本默认安装
conda install tensorflow-gpu

pip install --upgrade tensorflow
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

高版本安装

需要 pip安装 tensorflowhttps://tensorflow.google.cn/install/pip?hl=en#windows-native

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
#如果上面这个执行失败了,多执行几次
#如果自己的显卡支持,安装了上面的两个配置后,再安装下面的tensorflow-gpu 2.7.0版本的话
#就可以直接显示gpu版本的状态为为true
pip install tensorflow-gpu==2.7.0
pip install "tensorflow<2.11"
# 走清华镜像
-i https://pypi.tuna.tsinghua.edu.cn/simple
# 设置timeout
pip --default-timeout=600 install "tensorflow<2.11" -i https://pypi.tuna.tsinghua.edu.cn/simple
# Verify install:
#python
#impor tensorflow as tf
#print(tf.config.list_physical_devices('GPU'))

conda安装pytorch

选择版本安装:https://pytorch.org/get-started/locally/

conda create -n pytorch python=3.8
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

CondaSSLError: OpenSSL appears to be unavailable on this machine. OpenSSL is required to download and install packages. 解决的方法

  1. 到你的anaconda的安装目录位置:比如

  2. D:\ProgramData\Anaconda3\Library\bin,找到如下两个DLL的文件:

    libcrypto-1_1-x64.dll
    libssl-1_1-x64.dll

  3. 复制到 D:\ProgramData\Anaconda3\DLLs

  4. 重启下shell

测试

# tf
import tensorflow as tf
if tf.test.gpu_device_name():
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
print("Please install GPU version of TF")

import tensorflow as tf
print(tf.test.gpu_device_name())
print(tf.test.is_gpu_available())

# pytorch
import torch
flag = torch.cuda.is_available()
if flag:
print("CUDA可使用")
else:
print("CUDA不可用")

ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print("驱动为:",device)
print("GPU型号: ",torch.cuda.get_device_name(0))

conda常用命令

version:
conda -V
env:
conda env list
conda create -n env python=3.6
conda remove -n env --all
conda deactivate
Package:
conda list
conda list -n your_env_name
conda install -n env_name package_name
conda update -n env_name package_name
conda install numpy pandas matplotlib scikit-learn seaborn scikit-image opencv
conda update conda
conda update anaconda-navigator
conda update navigator-updater
conda update --all

numpy matplotlib scikit-image scikit-learn tqdm pandas global-land-mask netCDF4 gdal
------------------------------- 本文结束啦❤感谢您阅读-------------------------------
赞赏一杯咖啡