当前位置:   article > 正文

Anaconda搭建深度学习环境py 3.7:tensorflow-gpu2.3.0、pytorch1.12.1_gpu版本;(使用conda下载cuda和cudnn);配置环境经验总结_anaconda3.7

anaconda3.7

目录

前言:

0. 前提条件

(a). 安装Anaconda+pycharm

(b). Anaconda更改虚拟环境安装路径、创建虚拟环境

1. 创建虚拟环境(Python 3.7)

2. 安装tensorflow-gpu

(a). 常见版本匹配报错

(b). 下载tensorflow-gpu2.3.0版本

(c). 根据tensorflow-gpu下载相应的cudnn7.6.5版本

(d). 检验

(e). 报错及解决方案

报错1

报错2

3. 安装pytorch(gpu版本)

 (a). 官方

 (b). 清华源

4. 安装其它库

sklearn

matplotlib

keras-metrics

5. 配置环境总结


前言:

        本文使用conda下载cuda和cudnn,直接安装到虚拟环境,免去配置环境变量等操作且节省C盘空间。若想单独下载CUDA Toolkit及cudnn,可参照该文章:

【2022超详细版】Win10安装cuda(10.1、11.7)+cuDNN(7.6.5、8.5.0)+tensorflow(gpu版)+pytorch(gpu版)_QomolangmaH的博客-CSDN博客https://blog.csdn.net/m0_63834988/article/details/128781572?spm=1001.2014.3001.5501

        此外,配置环境会遇到n种报错,故本文下载版本及操作顺序不能乱

        若想安装其它版本,亦可参照本文提供的一些常见报错(我遇到的……)解决方案,或许大概可能有些参考价值吧……

        纯个人经验分享,仅供参考。若有不当之处,欢迎评论(虽然理论上,即使留言了我也不知道如何解决)

0. 前提条件

(a). 安装Anaconda+pycharm

win11 安装 Anaconda(2022.10)+pycharm(2022.3/2023.1.4)+配置虚拟环境_QomolangmaH的博客-CSDN博客https://blog.csdn.net/m0_63834988/article/details/128693741?spm=1001.2014.3001.5501

(b). Anaconda更改虚拟环境安装路径、创建虚拟环境

【2023】Anaconda更改虚拟环境安装路径+创建虚拟环境_anaconda修改虚拟环境安装位置_QomolangmaH的博客-CSDN博客https://blog.csdn.net/m0_63834988/article/details/128691854?spm=1001.2014.3001.5501

1. 创建虚拟环境(Python 3.7)

  • 创建名为"MLgpu"的新环境,并指定使用Python 3.7版本

conda create -n MLgpu python=3.7

  • 激活虚拟环境

conda activate MLgpu

2. 安装tensorflow-gpu

(a). 常见版本匹配报错

  1. ensorflow 2.3.0 requires scipy==1.4.1, but you have scipy 1.7.3 which is incompatible.
  2. tensorflow 2.3.0 requires tensorflow-estimator<2.4.0,>=2.3.0, but you have tensorflow-estimator 2.5.0 which is incompatible.
  3. tensorflow-gpu 2.3.0 requires scipy==1.4.1, but you have scipy 1.7.3 which is incompatible.

         scipy 和 tensorflow-estimator 版本与 TensorFlow 2.3.0 和 TensorFlow GPU 2.3.0 不兼容,可以尝试如下两种方法:

  • 升级 tensorFlow 和 tensorflow-gpu 版本
  • 降级安装 sciPy 和 tensorflow-estimator

        若选择第1种方法,可能会导致其它库的版本兼容性问题:如果有其他库依赖于 tensorflow-estimator 2.3.0 或 scipy 1.4.1 的特定版本,可能继续报错……然后继续改……

(b). 下载tensorflow-gpu2.3.0版本

须使用pip下载,实践表明conda下载后,安装pytorch会报错

pip install tensorflow-gpu==2.3.0

  1. Successfully installed MarkupSafe-2.1.2 absl-py-1.4.0 astunparse-1.6.3
  2. cachetools-5.3.0 certifi-2022.12.7 charset-normalizer-3.0.1 gast-0.3.3
  3. google-auth-2.16.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.51.1
  4. h5py-2.10.0 idna-3.4 importlib-metadata-6.0.0 keras-preprocessing-1.1.2
  5. markdown-3.4.1 numpy-1.18.5 oauthlib-3.2.2 opt-einsum-3.3.0 protobuf-3.20.3
  6. pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.28.2 requests-oauthlib-1.3.1
  7. rsa-4.9 scipy-1.4.1 six-1.16.0 tensorboard-2.11.2 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-gpu-2.3.0 tensorflow-gpu-estimator-2.3.0
  8. termcolor-2.2.0 typing-extensions-4.4.0 urllib3-1.26.14 werkzeug-2.2.2 wrapt-1.14.1
  9. zipp-3.12.0

(c). 根据tensorflow-gpu下载相应的cudnn7.6.5版本

使用如下conda会同时下载cudnn+cudatoolkit!!!

conda install cudnn==7.6.5

(d). 检验

  1. import tensorflow as tf
  2. print('GPU', tf.config.list_physical_devices('GPU'))
  3. a = tf.constant(3.)
  4. print(a * a)

(e). 报错及解决方案

下面的报错不知道是哪个版本遇到的了,最好不要遇见……

报错1

Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

2023-02-03 20:23:07.260374: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

且检测不出gpu,输出如下

  1. GPU []
  2. tf.Tensor(9.0, shape=(), dtype=float32)

原因:深度学习框架 TensorFlow 在尝试使用 CUDA 模块时出现版本匹配问题

解决方法:找到如下文件,复制粘贴并重命名为cudart64_101.dll

输出

GPU [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

报错2

AttributeError: module 'tensorflow.compat.v2' has no attribute '__internal__'

 keras与tensorflow版本不兼容

 conda install keras==2.4.3

  1. (RL) PS C:\Users\Lenovo> pip install keras==2.4.3
  2. Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
  3. Collecting keras==2.4.3
  4. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/44/e1/dc0757b20b56c980b5553c1b5c4c32d378c7055ab7bfa92006801ad359ab/Keras-2.4.3-py2.py3-none-any.whl (36 kB)
  5. Collecting pyyaml
  6. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d1/c0/4fe04181b0210ee2647cfbb89ecd10a36eef89f10d8aca6a192c201bbe58/PyYAML-6.0-cp37-cp37m-win_amd64.whl (153 kB)
  7. Requirement already satisfied: h5py in e:\software\anaconda3\envs\rl\lib\site-packages (from keras==2.4.3) (2.10.0)
  8. Requirement already satisfied: scipy>=0.14 in e:\software\anaconda3\envs\rl\lib\site-packages (from keras==2.4.3) (1.4.1)
  9. Requirement already satisfied: numpy>=1.9.1 in e:\software\anaconda3\envs\rl\lib\site-packages (from keras==2.4.3) (1.18.5)
  10. Requirement already satisfied: six in e:\software\anaconda3\envs\rl\lib\site-packages (from h5py->keras==2.4.3) (1.16.0)
  11. Installing collected packages: pyyaml, keras
  12. Successfully installed keras-2.4.3 pyyaml-6.0

3. 安装pytorch(gpu版本)

 (a). 官方

conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch

 (b). 清华源

(先前以添加清华源,详细步骤请参照文初链接)

conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1

(cudatoolkit=10.2在安装tensorflow-gpu时安装过了)

  1. environment location: E:\Software\anaconda3\envs\RLgpu
  2. added / updated specs:
  3. - pytorch==1.12.1
  4. - torchaudio==0.12.1
  5. - torchvision==0.13.1
  6. The following NEW packages will be INSTALLED:
  7. blas anaconda/cloud/conda-forge/win-64::blas-2.116-mkl
  8. blas-devel anaconda/cloud/conda-forge/win-64::blas-devel-3.9.0-16_win64_mkl
  9. brotlipy anaconda/cloud/conda-forge/win-64::brotlipy-0.7.0-py37hcc03f2d_1004
  10. certifi anaconda/cloud/conda-forge/noarch::certifi-2022.12.7-pyhd8ed1ab_0
  11. cffi anaconda/cloud/conda-forge/win-64::cffi-1.15.1-py37ha95fbe2_1
  12. charset-normalizer anaconda/cloud/conda-forge/noarch::charset-normalizer-2.1.1-pyhd8ed1ab_0
  13. cryptography anaconda/cloud/conda-forge/win-64::cryptography-38.0.2-py37h953a470_1
  14. freetype anaconda/cloud/conda-forge/win-64::freetype-2.12.1-h546665d_1
  15. idna anaconda/cloud/conda-forge/noarch::idna-3.4-pyhd8ed1ab_0
  16. intel-openmp anaconda/cloud/conda-forge/win-64::intel-openmp-2023.0.0-h57928b3_25922
  17. jpeg anaconda/cloud/conda-forge/win-64::jpeg-9e-h8ffe710_2
  18. lcms2 anaconda/cloud/conda-forge/win-64::lcms2-2.14-h90d422f_0
  19. lerc anaconda/cloud/conda-forge/win-64::lerc-4.0.0-h63175ca_0
  20. libblas anaconda/cloud/conda-forge/win-64::libblas-3.9.0-16_win64_mkl
  21. libcblas anaconda/cloud/conda-forge/win-64::libcblas-3.9.0-16_win64_mkl
  22. libdeflate anaconda/cloud/conda-forge/win-64::libdeflate-1.14-hcfcfb64_0
  23. libhwloc anaconda/cloud/conda-forge/win-64::libhwloc-2.8.0-h039e092_1
  24. libiconv anaconda/cloud/conda-forge/win-64::libiconv-1.17-h8ffe710_0
  25. liblapack anaconda/cloud/conda-forge/win-64::liblapack-3.9.0-16_win64_mkl
  26. liblapacke anaconda/cloud/conda-forge/win-64::liblapacke-3.9.0-16_win64_mkl
  27. libpng anaconda/cloud/conda-forge/win-64::libpng-1.6.39-h19919ed_0
  28. libtiff anaconda/cloud/conda-forge/win-64::libtiff-4.4.0-hc4f729c_5
  29. libuv anaconda/cloud/conda-forge/win-64::libuv-1.44.2-h8ffe710_0
  30. libwebp-base anaconda/cloud/conda-forge/win-64::libwebp-base-1.2.4-h8ffe710_0
  31. libxcb anaconda/cloud/conda-forge/win-64::libxcb-1.13-hcd874cb_1004
  32. libxml2 anaconda/cloud/conda-forge/win-64::libxml2-2.10.3-hc3477c8_0
  33. libzlib anaconda/cloud/conda-forge/win-64::libzlib-1.2.13-hcfcfb64_4
  34. m2w64-gcc-libgfor~ anaconda/cloud/conda-forge/win-64::m2w64-gcc-libgfortran-5.3.0-6
  35. m2w64-gcc-libs anaconda/cloud/conda-forge/win-64::m2w64-gcc-libs-5.3.0-7
  36. m2w64-gcc-libs-co~ anaconda/cloud/conda-forge/win-64::m2w64-gcc-libs-core-5.3.0-7
  37. m2w64-gmp anaconda/cloud/conda-forge/win-64::m2w64-gmp-6.1.0-2
  38. m2w64-libwinpthre~ anaconda/cloud/conda-forge/win-64::m2w64-libwinpthread-git-5.0.0.4634.697f757-2
  39. mkl anaconda/cloud/conda-forge/win-64::mkl-2022.1.0-h6a75c08_874
  40. mkl-devel anaconda/cloud/conda-forge/win-64::mkl-devel-2022.1.0-h57928b3_875
  41. mkl-include anaconda/cloud/conda-forge/win-64::mkl-include-2022.1.0-h6a75c08_874
  42. msys2-conda-epoch anaconda/cloud/conda-forge/win-64::msys2-conda-epoch-20160418-1
  43. numpy anaconda/cloud/conda-forge/win-64::numpy-1.21.6-py37h2830a78_0
  44. openjpeg anaconda/cloud/conda-forge/win-64::openjpeg-2.5.0-hc9384bd_1
  45. pillow anaconda/cloud/conda-forge/win-64::pillow-9.2.0-py37h42a8222_2
  46. pthread-stubs anaconda/cloud/conda-forge/win-64::pthread-stubs-0.4-hcd874cb_1001
  47. pthreads-win32 anaconda/cloud/conda-forge/win-64::pthreads-win32-2.9.1-hfa6e2cd_3
  48. pycparser anaconda/cloud/conda-forge/noarch::pycparser-2.21-pyhd8ed1ab_0
  49. pyopenssl anaconda/cloud/conda-forge/noarch::pyopenssl-23.0.0-pyhd8ed1ab_0
  50. pysocks anaconda/cloud/conda-forge/win-64::pysocks-1.7.1-py37h03978a9_5
  51. python_abi anaconda/cloud/conda-forge/win-64::python_abi-3.7-3_cp37m
  52. pytorch anaconda/cloud/pytorch/win-64::pytorch-1.12.1-py3.7_cpu_0
  53. pytorch-mutex anaconda/cloud/pytorch/noarch::pytorch-mutex-1.0-cpu
  54. requests anaconda/cloud/conda-forge/noarch::requests-2.28.2-pyhd8ed1ab_0
  55. tbb anaconda/cloud/conda-forge/win-64::tbb-2021.7.0-h91493d7_1
  56. tk anaconda/cloud/conda-forge/win-64::tk-8.6.12-h8ffe710_0
  57. torchaudio anaconda/cloud/pytorch/win-64::torchaudio-0.12.1-py37_cpu
  58. torchvision anaconda/cloud/pytorch/win-64::torchvision-0.13.1-py37_cpu
  59. typing_extensions anaconda/cloud/conda-forge/noarch::typing_extensions-4.4.0-pyha770c72_0
  60. urllib3 anaconda/cloud/conda-forge/noarch::urllib3-1.26.14-pyhd8ed1ab_0
  61. win_inet_pton anaconda/cloud/conda-forge/noarch::win_inet_pton-1.1.0-pyhd8ed1ab_6
  62. xorg-libxau anaconda/cloud/conda-forge/win-64::xorg-libxau-1.0.9-hcd874cb_0
  63. xorg-libxdmcp anaconda/cloud/conda-forge/win-64::xorg-libxdmcp-1.1.3-hcd874cb_0
  64. xz anaconda/cloud/conda-forge/win-64::xz-5.2.6-h8d14728_0
  65. zstd anaconda/cloud/conda-forge/win-64::zstd-1.5.2-h12be248_6

4. 安装其它库

sklearn

matplotlib

 conda install matplotlib
  1. The following NEW packages will be INSTALLED:
  2. brotli anaconda/cloud/conda-forge/win-64::brotli-1.0.9-hcfcfb64_8
  3. brotli-bin anaconda/cloud/conda-forge/win-64::brotli-bin-1.0.9-hcfcfb64_8
  4. bzip2 anaconda/cloud/conda-forge/win-64::bzip2-1.0.8-h8ffe710_4
  5. cycler anaconda/cloud/conda-forge/noarch::cycler-0.11.0-pyhd8ed1ab_0
  6. fonttools anaconda/pkgs/main/noarch::fonttools-4.25.0-pyhd3eb1b0_0
  7. freetype anaconda/cloud/conda-forge/win-64::freetype-2.12.1-h546665d_1
  8. gettext anaconda/cloud/conda-forge/win-64::gettext-0.21.1-h5728263_0
  9. glib anaconda/cloud/conda-forge/win-64::glib-2.74.1-h12be248_1
  10. glib-tools anaconda/cloud/conda-forge/win-64::glib-tools-2.74.1-h12be248_1
  11. gst-plugins-base anaconda/cloud/conda-forge/win-64::gst-plugins-base-1.21.3-h001b923_1
  12. gstreamer anaconda/cloud/conda-forge/win-64::gstreamer-1.21.3-h6b5321d_1
  13. icu anaconda/cloud/conda-forge/win-64::icu-70.1-h0e60522_0
  14. jpeg anaconda/cloud/conda-forge/win-64::jpeg-9e-h8ffe710_2
  15. kiwisolver anaconda/cloud/conda-forge/win-64::kiwisolver-1.4.4-py37h8c56517_0
  16. krb5 anaconda/cloud/conda-forge/win-64::krb5-1.20.1-heb0366b_0
  17. lerc anaconda/cloud/conda-forge/win-64::lerc-4.0.0-h63175ca_0
  18. libbrotlicommon anaconda/cloud/conda-forge/win-64::libbrotlicommon-1.0.9-hcfcfb64_8
  19. libbrotlidec anaconda/cloud/conda-forge/win-64::libbrotlidec-1.0.9-hcfcfb64_8
  20. libbrotlienc anaconda/cloud/conda-forge/win-64::libbrotlienc-1.0.9-hcfcfb64_8
  21. libclang anaconda/cloud/conda-forge/win-64::libclang-15.0.7-default_h77d9078_0
  22. libclang13 anaconda/cloud/conda-forge/win-64::libclang13-15.0.7-default_h77d9078_0
  23. libdeflate anaconda/cloud/conda-forge/win-64::libdeflate-1.17-hcfcfb64_0
  24. libffi anaconda/cloud/conda-forge/win-64::libffi-3.4.2-h8ffe710_5
  25. libglib anaconda/cloud/conda-forge/win-64::libglib-2.74.1-he8f3873_1
  26. libogg anaconda/cloud/conda-forge/win-64::libogg-1.3.4-h8ffe710_1
  27. libpng anaconda/cloud/conda-forge/win-64::libpng-1.6.39-h19919ed_0
  28. libtiff anaconda/cloud/conda-forge/win-64::libtiff-4.5.0-hf8721a0_2
  29. libvorbis anaconda/cloud/conda-forge/win-64::libvorbis-1.3.7-h0e60522_0
  30. libwebp anaconda/cloud/conda-forge/win-64::libwebp-1.2.4-hcfcfb64_1
  31. libwebp-base anaconda/cloud/conda-forge/win-64::libwebp-base-1.2.4-h8ffe710_0
  32. matplotlib anaconda/cloud/conda-forge/win-64::matplotlib-3.5.3-py37h03978a9_2
  33. matplotlib-base anaconda/cloud/conda-forge/win-64::matplotlib-base-3.5.3-py37hbaab90a_2
  34. munkres anaconda/cloud/conda-forge/noarch::munkres-1.1.4-pyh9f0ad1d_0
  35. packaging anaconda/cloud/conda-forge/noarch::packaging-23.0-pyhd8ed1ab_0
  36. pcre2 anaconda/cloud/conda-forge/win-64::pcre2-10.40-h17e33f8_0
  37. pillow anaconda/pkgs/main/win-64::pillow-9.3.0-py37hd77b12b_2
  38. ply anaconda/cloud/conda-forge/noarch::ply-3.11-py_1
  39. pyparsing anaconda/cloud/conda-forge/noarch::pyparsing-3.0.9-pyhd8ed1ab_0
  40. pyqt anaconda/cloud/conda-forge/win-64::pyqt-5.15.7-py37h35e25fb_0
  41. pyqt5-sip anaconda/cloud/conda-forge/win-64::pyqt5-sip-12.11.0-py37hf2a7229_0
  42. python-dateutil anaconda/cloud/conda-forge/noarch::python-dateutil-2.8.2-pyhd8ed1ab_0
  43. qt-main anaconda/cloud/conda-forge/win-64::qt-main-5.15.6-h9580fe5_6
  44. sip anaconda/cloud/conda-forge/win-64::sip-6.6.2-py37hf2a7229_0
  45. tk anaconda/cloud/conda-forge/win-64::tk-8.6.12-h8ffe710_0
  46. toml anaconda/cloud/conda-forge/noarch::toml-0.10.2-pyhd8ed1ab_0
  47. tornado anaconda/cloud/conda-forge/win-64::tornado-6.2-py37hcc03f2d_0
  48. xz anaconda/cloud/conda-forge/win-64::xz-5.2.6-h8d14728_0
  49. zstd anaconda/cloud/conda-forge/win-64::zstd-1.5.2-h12be248_6

keras-metrics

pip install keras-metrics

Successfully installed Keras-2.11.0 keras_metrics-1.1.0

5. 配置环境总结

        配置环境的痛苦……以下言论没有任何科学依据,仅供娱乐

  1. 我习惯先用conda配置
  2. pip不行就conda,conda报错就pip,核心思想:“瞎配”
  3. 版本不匹配一言不合就降版本
  4. 降版本:conda、pip一起来回删改会有奇迹发生(比如一个环境中同时存在好几个版本的numpy,但最后代码顺利运行)
  5. 自己配:一天配不完就配两天,两天配不完就配三天……整个十天八天没结果就放弃吧……建议寻找能人异士
  6. 本文谨针对requirement.txt完全不好用的情况


       

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/193868
推荐阅读
相关标签
  

闽ICP备14008679号