肝了四天,为了同时满足tensorflow-gpu和svm的运行,尝试了各种版本的两个库,终于找到一个兼容的了。
首先创建一个虚拟环境,可以参考我的
上一篇博客
在Anaconda Prompt中输入以下代码
conda create -n tf2.6py3.8-gpu python=3.8 # 创建虚拟环境,python选择3.8版本
activate tf2.6py3.8-gpu # 激活虚拟环境
首先,我用的服务器的cuda=11.2,cudnn=8.1,所以我选择tensorflow-gpu=2.6.0
按照matplotlib、numpy、sckit-learn、tensorflow、protobuf和keras的顺序安装。
pip install matplotlib==3.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install numpy==1.19.5 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-learn==0.24.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tensorflow-gpu==2.6.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install protobuf==3.20.0 -i https://pypi.tuna.tsinghua.edu.cn/simple # protobuf需要满足版本大于3.19.6且不超过3.20.x
pip install keras==2.6 -i https://pypi.tuna.tsinghua.edu.cn/simple
matlplotlib放在第一个安装时自动安装numpy包,但版本不是我们需要的,第二句可以把numpy包重新安装。
numpy的版本不能高于1.20,不然会报错。
protobuf需要满足版本大于3.19.6且不超过3.20.x。
改变protobuf和keras版本为了是解决导入tensorflow时引发的错误,以下是最终pip中的库。
Package Version
----------------------- ---------
absl-py 0.15.0
astunparse 1.6.3
cachetools 5.3.0
certifi 2022.12.7
charset-normalizer 3.1.0
clang 5.0
flatbuffers 1.12
gast 0.4.0
google-auth 2.17.3
google-auth-oauthlib 1.0.0
google-pasta 0.2.0
grpcio 1.54.0
h5py 3.1.0
idna 3.4
importlib-metadata 6.6.0
joblib 1.2.0
keras 2.6.0
Keras-Preprocessing 1.1.2
Markdown 3.4.3
MarkupSafe 2.1.2
numpy 1.19.5
oauthlib 3.2.2
opt-einsum 3.3.0
pip 23.1.2
protobuf 3.20.0
pyasn1 0.5.0
pyasn1-modules 0.3.0
requests 2.30.0
requests-oauthlib 1.3.1
rsa 4.9
scikit-learn 0.24.1
scipy 1.10.1
setuptools 67.7.2
six 1.15.0
tensorboard 2.13.0
tensorboard-data-server 0.7.0
tensorflow-estimator 2.12.0
tensorflow-gpu 2.6.0
termcolor 1.1.0
threadpoolctl 3.1.0
typing-extensions 3.7.4.3
urllib3 2.0.2
Werkzeug 2.3.3
wheel 0.40.0
wrapt 1.12.1
zipp 3.15.0
最后在pycharm中导入环境就行。
两个包导入成功。
版权声明:本文为jwj1766879377原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。