文章目录

cuda113 cudnn821重点内容前置9 代码实现log2. 正题:选择cuda11.3 cudnn 8.2.13. 安装pytorch1.10.0 GPU tensorflow-GPU 2.6.04.虚拟环境文件打包复制:5 具体dbug过程6 更新conda等信息7 其他信息:8 配置jupyter9 代码实现log

cuda113 cudnn821

重点内容前置

9 代码实现log

(py38torchtf) C:\Users\A_A>conda create -n py38torchtf python=3.8

(torch0508) C:\Users\A_A>conda activate py38torchtf

(py38torchtf) C:\Users\A_A>conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

(py38torchtf) C:\Users\A_A>python

Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import torch

>>> torch.cuda.is_available()

True

(py38torchtf) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple

>>> import tensorflow as tf

Traceback (most recent call last):

File "", line 1, in

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\__init__.py", line 41, in

from tensorflow.python.tools import module_util as _module_util

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\__init__.py", line 40, in

from tensorflow.python.eager import context

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\eager\context.py", line 32, in

from tensorflow.core.framework import function_pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in

from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in

from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in

from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in

from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in

_descriptor.FieldDescriptor(

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__

_message.Message._CheckCalledFromGeneratedFile()

TypeError: Descriptors cannot not be created directly.

If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.

If you cannot immediately regenerate your protos, some other possible workarounds are:

1. Downgrade the protobuf package to 3.20.x or lower.

2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

>>> exit()

(py38torchtf) C:\Users\A_A>pip install protobuf==3.20.1 -i https://pypi.douban.com/simple

Looking in indexes: https://pypi.douban.com/simple

(py38torchtf) C:\Users\A_A>python

Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>> tf.test.is_gpu_available()

WARNING:tensorflow:From :1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.

Instructions for updating:

Use `tf.config.list_physical_devices('GPU')` instead.

2023-05-09 21:02:58.664337: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

2023-05-09 21:03:00.923971: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 2149 MB memory: -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5

True

>>> tf.test.is_built_with_cuda()

True

>>> exit()

(py38torchtf) C:\Users\A_A>

(py38torchtf) C:\Users\A_A>pip install ipykernel -i https://pypi.douban.com/simple

(py38torchtf) C:\Users\A_A>python -m ipykernel install --user --name py38torchtf

Installed kernelspec py38torchtf in C:\Users\A_A\AppData\Roaming\jupyter\kernels\py38torchtf

(py38torchtf) C:\Users\A_A>

(py38torchtf) C:\Users\A_A>cd /d D:\Auser

(py38torchtf) D:\Auser>jupyter notebook

## 剩下的虚拟环境报错说http等原因,仍然没能解决,以后用上面的install来做吧

当前windows中有NVIDIA GeForce GTX 1650 ,驱动版本:512.89, 需要配套哪个版本的cuda和cudnn,用来兼容安装pytorch-gpu和tensorflow-gpu,并给出兼容的pytorch-GPU版本和tensorflow-GPU版本

总结:

1)当conda安装提示需要更新numpy才可以安装tensor,并尝试numpy安装仍然不成功之后需要用pip的方式安装tensor;仍然有问题,根据提示安装相关包即可。

2)完成上述工作需要将上述内容总结,并完成虚拟环境配置的复制,尽量整理到封装的docker之类的信息中。

2. 正题:选择cuda11.3 cudnn 8.2.1

很完整cuda和cudnn安装的参考资料:https://blog.csdn.net/m0_45447650/article/details/123704930

一次性安装tensorflow torch参考资料:https://blog.csdn.net/xiao_yun_zi/article/details/124046964

cuda:https://developer.nvidia.com/cuda-toolkit-archive

cudnn:https://developer.nvidia.com/rdp/cudnn-archive

cudnn安装成功提示:https://blog.csdn.net/qq_40968179/article/details/124240224

3. 安装pytorch1.10.0 GPU tensorflow-GPU 2.6.0

Pytorch官网

https://pytorch.org/get-started/previous-versions/

(torch0508) C:\Users\A_A>conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

(torch0508) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simplepy

==> 这里还要添加 pip install protobuf==3.20.1 具体看下一步import tensorflow之后的信息

安装pytorch 成功

>>>torch.cuda.is_available()

True

>>>torch.__version__

'1.10.0'

安装tensorflow-gpu2.6.0 成功

测试参考文献:https://blog.csdn.net/yuan2019035055/article/details/129901579

>>> tf.test.is_gpu_available()

WARNING:tensorflow:From :1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.

Instructions for updating:

Use `tf.config.list_physical_devices('GPU')` instead.

2023-05-09 01:39:58.018763: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

2023-05-09 01:40:07.189620: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 2149 MB memory: -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5

True

>>>tf.config.list_physical_devices('GPU')

>>>True

import tensorflow as tf

print(tf.test.is_built_with_cuda())

print(tf.test.is_gpu_available())

tensorflow 和cuda对照表:

https://tensorflow.google.cn/install/source_windows?hl=zh-cn#gpu

pytorch: 离线安装参考文献:

https://blog.csdn.net/Despereaux_/article/details/129322034

4.虚拟环境文件打包复制:

虚拟文件打包迁移参考文件:https://www.codenong.com/cd7c0e626aedc335011d/

将windows中的conda虚拟环境删除

conda remove --name --all

备份虚拟环境,以防止当前环境因为后期开发问题导致使用失败:

To copy a conda virtual environment in Windows, you can follow these steps:

Open the Anaconda prompt or any command prompt that has access to conda.Activate the source environment that you want to copy by typing the following command: conda activate source_env where “source_env” is the name of the environment that you want to copy.Export the environment specifications to a YAML file using the following command: conda env export > environment.ymlCreate a new environment with the same packages and dependencies as the source environment by running the following command: conda env create -f environment.yml -n new_env where “new_env” is the name of the new environment that you want to create.Activate the new environment by running the following command: conda activate new_env

实测:

(torch0508) C:\Users\A_A>conda env export > cuda113cudnn821torch10tensor26.yml

5 具体dbug过程

使用pip安装tensorflow:

(torch0508) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple

Looking in indexes: https://pypi.douban.com/simple

Collecting tensorflow-gpu==2.6.0

Downloading https://pypi.doubanio.com/packages/2f/ad/c16cfadfc4c80e13a8679d556aa849fc34dcd2f2ba078d224a68a0809743/tensorflow_gpu-2.6.0-cp38-cp38-win_amd64.whl (423.3 MB)

---------------------------------------- 423.3/423.3 MB 1.5 MB/s eta 0:00:00

Requirement already satisfied: grpcio<2.0,>=1.37.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (1.51.1)

Collecting absl-py~=0.10

Using cached https://pypi.doubanio.com/packages/97/75/f5e61fb67ecbe45c31035b17562464e11b91a2b8a351bae5ca0db2969e3b/absl_py-0.15.0-py3-none-any.whl (132 kB)

Requirement already satisfied: wheel~=0.35 in d:\aworkstation\anaconda3\envs\torch0508\lib\site-packages (from tensorflow-gpu==2.6.0) (0.38.4)

Requirement already satisfied: google-pasta~=0.2 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (0.2.0)

Collecting flatbuffers~=1.12.0

Using cached https://pypi.doubanio.com/packages/eb/26/712e578c5f14e26ae3314c39a1bdc4eb2ec2f4ddc89b708cf8e0a0d20423/flatbuffers-1.12-py2.py3-none-any.whl (15 kB)

Collecting wrapt~=1.12.1

Using cached wrapt-1.12.1-cp38-cp38-win_amd64.whl

Collecting termcolor~=1.1.0

Using cached termcolor-1.1.0-py3-none-any.whl

Requirement already satisfied: keras-preprocessing~=1.1.2 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (1.1.2)

Requirement already satisfied: gast==0.4.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (0.4.0)

Collecting six~=1.15.0

Using cached https://pypi.doubanio.com/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl (10 kB)

Collecting clang~=5.0

Using cached clang-5.0-py3-none-any.whl

Collecting h5py~=3.1.0

Using cached https://pypi.doubanio.com/packages/93/3a/f94b993a8db766983b972f5905cb3f0e655bcb6620088fa2b9141e74ff36/h5py-3.1.0-cp38-cp38-win_amd64.whl (2.7 MB)

Collecting keras~=2.6

Using cached https://pypi.doubanio.com/packages/d5/80/34e55d7e3ed9cf18020929460f969de1bf82cf2f509c639b358ae2b25618/keras-2.12.0-py2.py3-none-any.whl (1.7 MB)

Collecting typing-extensions~=3.7.4

Using cached https://pypi.doubanio.com/packages/60/7a/e881b5abb54db0e6e671ab088d079c57ce54e8a01a3ca443f561ccadb37e/typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)

Collecting tensorboard~=2.6

Using cached https://pypi.doubanio.com/packages/aa/80/f7233129f75d0d1b35e67df3a48010fffd21ccde124847e3c33d503fef01/tensorboard-2.12.2-py3-none-any.whl (5.6 MB)

Collecting protobuf>=3.9.2

Using cached https://pypi.doubanio.com/packages/25/ca/79af03ceec0f9439d8fb5c2c8d99454c5c4f8c7fe00c8e7dbb280a8177c8/protobuf-4.22.3-cp38-cp38-win_amd64.whl (420 kB)

Requirement already satisfied: opt-einsum~=3.3.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (3.3.0)

Collecting tensorflow-estimator~=2.6

Using cached https://pypi.doubanio.com/packages/d1/e1/c3596da404e2c47561a2bb392397208925e65be6f61bd3081e630371d5e8/tensorflow_estimator-2.12.0-py2.py3-none-any.whl (440 kB)

Collecting numpy~=1.19.2

Using cached https://pypi.doubanio.com/packages/5a/13/25a83b9aae5fe9460b1997f5ba48814783d7f460bbbd8cadd96e1481ddf0/numpy-1.19.5-cp38-cp38-win_amd64.whl (13.3 MB)

Requirement already satisfied: astunparse~=1.6.3 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorflow-gpu==2.6.0) (1.6.3)

Requirement already satisfied: setuptools>=41.0.0 in d:\aworkstation\anaconda3\envs\torch0508\lib\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (66.0.0)

Collecting google-auth-oauthlib<1.1,>=0.5

Using cached https://pypi.doubanio.com/packages/4a/07/8d9a8186e6768b55dfffeb57c719bc03770cf8a970a074616ae6f9e26a57/google_auth_oauthlib-1.0.0-py2.py3-none-any.whl (18 kB)

Collecting tensorboard-plugin-wit>=1.6.0

Using cached https://pypi.doubanio.com/packages/e0/68/e8ecfac5dd594b676c23a7f07ea34c197d7d69b3313afdf8ac1b0a9905a2/tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)

Requirement already satisfied: markdown>=2.6.8 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (3.4.1)

Requirement already satisfied: werkzeug>=1.0.1 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (2.2.2)

Collecting tensorboard-data-server<0.8.0,>=0.7.0

Using cached https://pypi.doubanio.com/packages/9d/cc/6f07c0043b44b3c3879ecfec1b8a450b6f5e3f8dccfedc9f5f1bc2c650e6/tensorboard_data_server-0.7.0-py3-none-any.whl (2.4 kB)

Collecting google-auth<3,>=1.6.3

Using cached https://pypi.doubanio.com/packages/da/cc/13eb3d0b151252e1d2bafc52f412be05c3789b0f655caf5eed298cf8056c/google_auth-2.17.3-py2.py3-none-any.whl (178 kB)

Requirement already satisfied: requests<3,>=2.21.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from tensorboard~=2.6->tensorflow-gpu==2.6.0) (2.28.2)

Collecting pyasn1-modules>=0.2.1

Downloading https://pypi.doubanio.com/packages/cd/8e/bea464350e1b8c6ed0da3a312659cb648804a08af6cacc6435867f74f8bd/pyasn1_modules-0.3.0-py2.py3-none-any.whl (181 kB)

---------------------------------------- 181.3/181.3 kB 3.6 MB/s eta 0:00:00

Collecting cachetools<6.0,>=2.0.0

Using cached https://pypi.doubanio.com/packages/db/14/2b48a834d349eee94677e8702ea2ef98b7c674b090153ea8d3f6a788584e/cachetools-5.3.0-py3-none-any.whl (9.3 kB)

Collecting rsa<5,>=3.1.4

Using cached https://pypi.doubanio.com/packages/49/97/fa78e3d2f65c02c8e1268b9aba606569fe97f6c8f7c2d74394553347c145/rsa-4.9-py3-none-any.whl (34 kB)

Requirement already satisfied: requests-oauthlib>=0.7.0 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from google-auth-oauthlib<1.1,>=0.5->tensorboard~=2.6->tensorflow-gpu==2.6.0) (1.3.1)

Requirement already satisfied: importlib-metadata>=4.4 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from markdown>=2.6.8->tensorboard~=2.6->tensorflow-gpu==2.6.0) (6.0.0)

Collecting urllib3<1.27,>=1.21.1

Using cached https://pypi.doubanio.com/packages/7b/f5/890a0baca17a61c1f92f72b81d3c31523c99bec609e60c292ea55b387ae8/urllib3-1.26.15-py2.py3-none-any.whl (140 kB)

Requirement already satisfied: certifi>=2017.4.17 in d:\aworkstation\anaconda3\envs\torch0508\lib\site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow-gpu==2.6.0) (2022.12.7)

Requirement already satisfied: idna<4,>=2.5 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from requests<3,>=2.21.0->tensorboard~=2.6->tensorflow-gpu==2.6.0) (3.4)

Collecting charset-normalizer<4,>=2

Using cached https://pypi.doubanio.com/packages/26/20/83e1804a62b25891c4e770c94d9fd80233bbb3f2a51c4fadee7a196e5a5b/charset_normalizer-3.1.0-cp38-cp38-win_amd64.whl (96 kB)

Requirement already satisfied: MarkupSafe>=2.1.1 in c:\users\a_a\appdata\roaming\python\python38\site-packages (from werkzeug>=1.0.1->tensorboard~=2.6->tensorflow-gpu==2.6.0) (2.1.2)

Collecting zipp>=0.5

Using cached https://pypi.doubanio.com/packages/5b/fa/c9e82bbe1af6266adf08afb563905eb87cab83fde00a0a08963510621047/zipp-3.15.0-py3-none-any.whl (6.8 kB)

Collecting pyasn1<0.6.0,>=0.4.6

Downloading https://pypi.doubanio.com/packages/14/e5/b56a725cbde139aa960c26a1a3ca4d4af437282e20b5314ee6a3501e7dfc/pyasn1-0.5.0-py2.py3-none-any.whl (83 kB)

---------------------------------------- 83.9/83.9 kB 4.6 MB/s eta 0:00:00

Collecting oauthlib>=3.0.0

Using cached https://pypi.doubanio.com/packages/7e/80/cab10959dc1faead58dc8384a781dfbf93cb4d33d50988f7a69f1b7c9bbe/oauthlib-3.2.2-py3-none-any.whl (151 kB)

Installing collected packages: wrapt, typing-extensions, termcolor, tensorboard-plugin-wit, flatbuffers, clang, zipp, urllib3, tensorflow-estimator, tensorboard-data-server, six, pyasn1, protobuf, oauthlib, numpy, keras, charset-normalizer, cachetools, rsa, pyasn1-modules, h5py, absl-py, google-auth, google-auth-oauthlib, tensorboard, tensorflow-gpu

Attempting uninstall: typing-extensions

Found existing installation: typing_extensions 4.5.0

Uninstalling typing_extensions-4.5.0:

Successfully uninstalled typing_extensions-4.5.0

Attempting uninstall: numpy

Found existing installation: numpy 1.24.3

Uninstalling numpy-1.24.3:

Successfully uninstalled numpy-1.24.3

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

torchtext 0.15.1 requires tqdm, which is not installed.

spacy 3.4.4 requires catalogue<2.1.0,>=2.0.6, which is not installed.

spacy 3.4.4 requires cymem<2.1.0,>=2.0.2, which is not installed.

spacy 3.4.4 requires jinja2, which is not installed.

spacy 3.4.4 requires langcodes<4.0.0,>=3.2.0, which is not installed.

spacy 3.4.4 requires murmurhash<1.1.0,>=0.28.0, which is not installed.

spacy 3.4.4 requires packaging>=20.0, which is not installed.

spacy 3.4.4 requires pathy>=0.3.5, which is not installed.

spacy 3.4.4 requires preshed<3.1.0,>=3.0.2, which is not installed.

spacy 3.4.4 requires smart-open<7.0.0,>=5.2.1, which is not installed.

spacy 3.4.4 requires spacy-legacy<3.1.0,>=3.0.10, which is not installed.

spacy 3.4.4 requires spacy-loggers<2.0.0,>=1.0.0, which is not installed.

spacy 3.4.4 requires srsly<3.0.0,>=2.4.3, which is not installed.

spacy 3.4.4 requires thinc<8.2.0,>=8.1.0, which is not installed.

spacy 3.4.4 requires tqdm<5.0.0,>=4.38.0, which is not installed.

spacy 3.4.4 requires wasabi<1.1.0,>=0.9.1, which is not installed.

matplotlib 3.6.3 requires contourpy>=1.0.1, which is not installed.

matplotlib 3.6.3 requires cycler>=0.10, which is not installed.

matplotlib 3.6.3 requires fonttools>=4.22.0, which is not installed.

matplotlib 3.6.3 requires packaging>=20.0, which is not installed.

matplotlib 3.6.3 requires pillow>=6.2.0, which is not installed.

matplotlib 3.6.3 requires pyparsing>=2.2.1, which is not installed.

matplotlib 3.6.3 requires python-dateutil>=2.7, which is not installed.

imbalanced-learn 0.9.1 requires joblib>=1.0.0, which is not installed.

imbalanced-learn 0.9.1 requires scikit-learn>=1.1.0, which is not installed.

imbalanced-learn 0.9.1 requires scipy>=1.3.2, which is not installed.

imbalanced-learn 0.9.1 requires threadpoolctl>=2.0.0, which is not installed.

d2l 0.17.5 requires pandas==1.2.4, which is not installed.

torchtext 0.15.1 requires torch==2.0.0, but you have torch 1.10.0 which is incompatible.

torchdata 0.6.0 requires torch==2.0.0, but you have torch 1.10.0 which is incompatible.

d2l 0.17.5 requires matplotlib==3.5.1, but you have matplotlib 3.6.3 which is incompatible.

d2l 0.17.5 requires numpy==1.21.5, but you have numpy 1.19.5 which is incompatible.

d2l 0.17.5 requires requests==2.25.1, but you have requests 2.28.2 which is incompatible.

Successfully installed absl-py-0.15.0 cachetools-5.3.0 charset-normalizer-3.1.0 clang-5.0 flatbuffers-1.12 google-auth-2.17.3 google-auth-oauthlib-1.0.0 h5py-3.1.0 keras-2.12.0 numpy-1.19.5 oauthlib-3.2.2 protobuf-4.22.3 pyasn1-0.5.0 pyasn1-modules-0.3.0 rsa-4.9 six-1.15.0 tensorboard-2.12.2 tensorboard-data-server-0.7.0 tensorboard-plugin-wit-1.8.1 tensorflow-estimator-2.12.0 tensorflow-gpu-2.6.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.15 wrapt-1.12.1 zipp-3.15.0

(torch0508) C:\Users\A_A>python

Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

Traceback (most recent call last):

File "", line 1, in

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\__init__.py", line 41, in

from tensorflow.python.tools import module_util as _module_util

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\python\__init__.py", line 40, in

from tensorflow.python.eager import context

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\python\eager\context.py", line 32, in

from tensorflow.core.framework import function_pb2

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in

from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in

from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in

from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in

from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in

_descriptor.FieldDescriptor(

File "D:\AworkStation\Anaconda3\envs\torch0508\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__

_message.Message._CheckCalledFromGeneratedFile()

TypeError: Descriptors cannot not be created directly.

If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.

If you cannot immediately regenerate your protos, some other possible workarounds are:

1. Downgrade the protobuf package to 3.20.x or lower.

2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

>>>

参考解决方案:

https://blog.csdn.net/weixin_44808574/article/details/128225048

pip install protobuf==3.20.1

tf.test.is_gpu_available()

6 更新conda等信息

更新conda:

conda update -n base -c defaults conda

更新pip:

conda upgrade pip

conda upgrade conda

7 其他信息:

当时尝试了很多版本都不成功,主要问题是tensor死活上不去,pytorch没事,包括conda和pip都用了就是不行。

重构计划:将原来显卡的非必要驱动,通过控制面板的程序卸载,将原来的cudnn8.9 改成cudnn8.2.1,重装cuda11.3,使用了某管家清理注册表。

卸载参考:https://blog.csdn.net/weixin_44606139/article/details/127493438

如果遇到http或者等镜像问题,可以参考以下解决方案:

更改镜像源:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

当时使用env_copy.yml 文件生成新的env的时候,出现了以下信息:

raise ReadTimeoutError(self._pool, None, "Read timed out.")

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

failed

CondaEnvException: Pip failed

可以考虑更换镜像为国内源。但是我没能成功解决

8 配置jupyter

参考文献:https://blog.csdn.net/qq_43203949/article/details/108524056

# 模板

pip install ipykernel

# 实测:

(torch0508) C:\Users\A_A>pip install ipykernel -i https://pypi.douban.com/simple --user

# 模板

python -m ipykernel install --user --name env_name

# 实测

(torch0508) C:\Users\A_A>python -m ipykernel install --user --name torch0508

Installed kernelspec torch0508 in C:\Users\A_A\AppData\Roaming\jupyter\kernels\torch0508

9 代码实现log

(py38torchtf) C:\Users\A_A>conda create -n py38torchtf python=3.8

(torch0508) C:\Users\A_A>conda activate py38torchtf

(py38torchtf) C:\Users\A_A>conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

(py38torchtf) C:\Users\A_A>python

Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import torch

>>> torch.cuda.is_available()

True

(py38torchtf) C:\Users\A_A>pip install tensorflow-gpu==2.6.0 -i https://pypi.douban.com/simple

>>> import tensorflow as tf

Traceback (most recent call last):

File "", line 1, in

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\__init__.py", line 41, in

from tensorflow.python.tools import module_util as _module_util

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\__init__.py", line 40, in

from tensorflow.python.eager import context

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\python\eager\context.py", line 32, in

from tensorflow.core.framework import function_pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in

from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in

from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in

from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in

from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in

_descriptor.FieldDescriptor(

File "D:\AworkStation\Anaconda3\envs\py38torchtf\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__

_message.Message._CheckCalledFromGeneratedFile()

TypeError: Descriptors cannot not be created directly.

If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.

If you cannot immediately regenerate your protos, some other possible workarounds are:

1. Downgrade the protobuf package to 3.20.x or lower.

2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

>>> exit()

(py38torchtf) C:\Users\A_A>pip install protobuf==3.20.1 -i https://pypi.douban.com/simple

Looking in indexes: https://pypi.douban.com/simple

(py38torchtf) C:\Users\A_A>python

Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>> tf.test.is_gpu_available()

WARNING:tensorflow:From :1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.

Instructions for updating:

Use `tf.config.list_physical_devices('GPU')` instead.

2023-05-09 21:02:58.664337: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

2023-05-09 21:03:00.923971: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 2149 MB memory: -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5

True

>>> tf.test.is_built_with_cuda()

True

>>> exit()

(py38torchtf) C:\Users\A_A>

(py38torchtf) C:\Users\A_A>pip install ipykernel -i https://pypi.douban.com/simple

(py38torchtf) C:\Users\A_A>python -m ipykernel install --user --name py38torchtf

Installed kernelspec py38torchtf in C:\Users\A_A\AppData\Roaming\jupyter\kernels\py38torchtf

(py38torchtf) C:\Users\A_A>

(py38torchtf) C:\Users\A_A>cd /d D:\Auser

(py38torchtf) D:\Auser>jupyter notebook

## 剩下的备份虚拟环境报错说http等原因,仍然没能解决,当前解决方案还是用到新的项目就create 一个新的env,然后再install tensorflow和torch 比较靠谱

精彩文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。