anaconda+pycharm

新装上任,不适合新手看,不够详细,只是自己后期换电脑再次安装的一个记录。

目录

1. 安装anaconda

1.1 配置环境变量

1.2 配置conda

1.3 查看conda信息        

1.4 配置pip镜像源 

2 . 搭环境

2.1 查看显卡驱动版本

2.2 安装cuda 

2.3 安装CuDNN(加速器)

2.4 安装pytorch

2.5 安装tensorflow

Anaconda常用命令 


1. 安装anaconda

官网安装太慢,选择anaconda的清华镜像源

清华镜像源        选择了一个不新不旧的版本,小废物表示最新版本我不敢。安装过程改改路径,基本上就是Next,可以参考相关。

1.1 配置环境变量

D:\Data_anaconda2023 

D:\Data_anaconda2023 \Scripts 

D:\Data_anaconda2023 \Library\mingw-w64\bin

D:\Data_anaconda2023 \Library\usr\bin 

D:\Data_anaconda2023 \Library\bin

1.2 配置conda

(虚拟环境安装位置、包下载位置、conda下载通道等)

最好不要换虚拟环境的安装位置!!!不然在cmd检测不到虚拟环境,反正最好别换,因为base的位置已经换了,所以不改也在D盘。不影响。

改了的话,pycharm中的CMD可能没有进到虚拟环境,我不知道是pycharm版本问题还是具体什么问题。 

C:\Users\1111(你自己的用户名)        该路径下如果没有.condarc文件,自行创建记事本文件(显示文件扩展名,才好修改),然后再重命名改成.condarc

 在该文件中配置相应信息,换源。

show_channel_urls: true
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - defaults

1.3 查看conda信息        

conda info

(base) C:\Windows\System32>conda info

     active environment : base
    active env location : D:\ProgramData\anaconda3
            shell level : 1
       user config file : C:\Users\15808\.condarc
 populated config files : C:\Users\15808\.condarc
          conda version : 23.7.4
    conda-build version : 3.26.1
         python version : 3.11.5.final.0
       virtual packages : __archspec=1=x86_64
                          __cuda=12.3=0
                          __win=0=0
       base environment : D:\ProgramData\anaconda3  (writable)
      conda av data dir : D:\ProgramData\anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/win-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/noarch
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/win-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/noarch
          package cache : D:\All_Project_Will_do\anaconda_evns_L\pkgs
       envs directories : D:\All_Project_Will_do\anaconda_envs_L\envs
                          D:\ProgramData\anaconda3\envs
                          C:\Users\15808\.conda\envs
                          C:\Users\15808\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/23.7.4 requests/2.31.0 CPython/3.11.5 Windows/10 Windows/10.0.22631 aau/0.4.2 c/a1RnixqCYKEGxLkLugMRTw s/PyrGpy8pGf5f_zxevCf95g e/vKw6FCxY0mTlIDjmorkQeg
          administrator : True
             netrc file : None
           offline mode : False

后面我把.condarc文件改动的虚拟环境地址删了,就回到了默认的anaconda下的envs下面。 

1.4 配置pip镜像源 

临时使用 :

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-packag

更新pip,并配置全局镜像源:

python -m pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
使用镜像更新pip:

python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip

直接在pip.ini文件中修改也行 

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple 

2 . 搭环境

搭个稳定一点的通用试试

 conda create -n Lhh_Project python=3.8 -y  

2.1 查看显卡驱动版本

nvidia-smi

2.2 安装cuda 

cuda 官网地址

选择低于自己驱动的版本下载,这里下载了12.2  。如果想下载给更高版本,可以去英伟达官网升级驱动。cuda向下兼容。

下载好后,双击安装包进行安装,可以安装在自定义的目录文件夹下,NO ,我更改了也没有,然后找都找不到,还是通过everything找的。

查看是否安装成功

nvcc  -V

 报错,因为没设置环境变量,且我改了安装路径。但是默认会到这里,在终端运行这两个程序,PASS即通过,安装没问题,就是要去配环境变量/

运行bandwidthTest.exe 和 deviceQuery.exe

 测试通过

 建议还是不要改路径啊,找都找不到,避免不必要的麻烦,要改也只改前面的盘名C--->D  其他的不变。

2.3 安装CuDNN(加速器)

cuDNN安装路径        (安装时改了好像也没用):

C:\Program Files\NVIDIA\CUDNN\v9.5


 cuda 的安装路径C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2下并覆盖。


cd到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\extras\demo_suite,或者直接进入该目录然后打开终端。然后分别执行

bandwidthTest.exe
deviceQuery.exe

PASS 即通过,perfect!

2.4 安装pytorch

2.4.1 在线安装

pip直接走官网链接安装要很久,使用镜像源的话就只能下载到cpu版本。(pip install 时不要用魔法)

因此要使用pip就还是建议离线安装

PyTorch官网,不要直接在这个页面装,这样子看不到torch的版本

 进以前的版本找需要的

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113    

然后最好不要按它这个,这样子不会走镜像下载,要下很久,建议后面改个临时镜像。不改的下下来它的安装源是pypi。

可根据下列命令:

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 -i https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://download.pytorch.org/whl/cu113 --trusted-host pypi.tuna.tsinghua.edu.cn

其中:-i指定了默认的索引URL(清华镜像),而--extra-index-url添加了官方的PyTorch索引,这样pip就会首先从清华镜像尝试下载,如果找不到,再从官方源下载。

 然后我发现配了应该也没用,笑死了。可以试试,大抵还是要魔法好一点。

 装好了去测试

2.4.2 离线安装

官网确定要安装的版本

先下轮子再安装,到  wheel网站,进入torch、torchvision、torchaudio 三大组件各自的网站。我们在这三个组件各自的网站里Ctrl + F搜索 对应版本。例如搜索 2.1.0+cu121 

找到对应的文件下载。

 下载好后,将三个whl文件放在新建的D:\whl文件夹中。 安装命令为

pip install 路径\轮子名.whl,即:

pip install D:\whl\torch-1.12.0+cu113-cp39-cp39-win_amd64.whl

pip install D:\whl\torchvision-0.13.0+cu113-cp39-cp39-win_amd64.whl

pip install D:\whl\torchaudio-0.12.0+cu113-cp39-cp39-win_amd64.whl

然后就可以拷贝环境以后直接用。

conda create --name <new_env_name> --clone <old_env_name>
        conda create --name L --clone Lbase 

2.5 安装tensorflow

 tensorflow  版本对应关系        官网

安装指南,我直接根据博客的版本安装的,在虚拟环境中又装了cuda和cudnn。博客 

记得更新pip,魔法好像也会影响,不懂。

pip install tensorflow-gpu==2.10.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

tensorflow

conda search tensorflow-gpu  # 查看有哪些版本

 其他包的安装最好还是不在pycharm中安装,去conda里面装吧

Anaconda常用命令 

# 创建一个新的Anaconda环境
conda create --name myenv python=3.8

# 激活一个已创建的Anaconda环境
conda activate myenv

# 退出当前激活的Anaconda环境
conda deactivate

# 列出所有已创建的Anaconda环境
conda env list

# 删除一个Anaconda环境
conda env remove --name myenv

# 在当前环境中安装一个包
conda install numpy

# 在指定环境中安装一个包
conda install --name myenv numpy

# 安装及卸载
conda  install  xx=版本号  # 指定版本号
conda  install  xxx -i 源名称或链接 # 指定下载源
conda  uninstall  xxx

# 更新环境中的所有包
conda update --all

# 更新环境中的特定包
conda update numpy

# 卸载环境中的特定包
conda remove numpy

# 查找可以安装的包版本
conda search numpy

# 清理Anaconda缓存,释放空间
conda clean --all

# 清除缓存
pip cache purge 

# 查看conda的配置信息
conda config --show

# 添加一个channel(源),比如添加清华大学的镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

# 移除一个channel
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

# 显示所有已添加的channels
conda config --show channels

# 使用指定channel安装包
conda install --channel https://conda.anaconda.org/conda-forge scipy

# 克隆一个环境
conda create --name myclone --clone myenv

# 导出一个环境的依赖关系到一个YAML文件
conda env export > environment.yml

# 从一个YAML文件创建一个环境
conda env create -f environment.yml

# 删除cuda    (cuda和cudnn会一起消失)
conda uninstall cudatoolkit


# 查看是否有可用GPU、可用GPU数量:
torch.cuda.is_available(), torch.cuda.device_count()
或者
import tensorflow as tf
version=tf.__version__  #输出tensorflow版本
gpu_ok=tf.test.is_gpu_available()  #输出gpu可否使用
print("tf version:",version,"\nuse GPU:",gpu_ok)

 next time~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值