当然 在这之前 你需要安装anaconda,略…
numpy==1.19.2
pip install --target=d:\anaconda3\lib\site-packages (1.19.5) numpy==1.19.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
选择这两个版本的原因是:
当前的tf是2.6.0 对应的numpy 是1.19.2
(base) PS C:\Users\lenovo> pip install numpy -i
https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes:
https://pypi.tuna.tsinghua.edu.cn/simple Requirement already
satisfied: numpy in d:\anaconda3\lib\site-packages (1.19.5)
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.
tensorflow 2.6.0 requires numpy~=1.19.2, but you have numpy 1.21.2 which is incompatible.
tensorflow==2.6.0
pip install -U tensorflow==2.6.0 --target=d:\anaconda3\lib\site-packages (2.6.0) -i https://pypi.tuna.tsinghua.edu.cn/simple
报错
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.
spyder 4.2.5 requires pyqt5<5.13, which is not installed.
spyder 4.2.5 requires pyqtwebengine<5.13, which is not installed.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.9.1 requires ruamel-yaml, which is not installed.
对应四个错误提示的补丁
pip install pyqtwebengine==5.12 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyqt5==5.12 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pathlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install ruamel-yaml -i https://pypi.tuna.tsinghua.edu.cn/simple
运行
(base) PS C:\Users\lenovo> ipython
In [1]: import tensorflow as tf
2021-10-12 14:33:33.656932: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-10-12 14:33:33.670924: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
In [2]: tf.__version__
Out[2]: '2.6.0'
关于两个 警告:
使用新的Tensorflow 2.1版本,默認的tensorflow
pip包含TF的CPU和GPU版本,在以前的tF版本中,找不到CUDA庫會發出一個錯誤,並引發一個異常,而現在這個庫會自動搜索正確的CUDA版本,如果找不到它,就會發出警告(W代表警告,錯誤是E(或F代表致命錯誤),並返回到CPU模式,2020-01-20
12:27:44.554767 : W
tensorflow/stream_executor/platform/default/dso_loader.cc:55] could
not load dynamic library’cudart64_101.dll’; dlerror : cudart64_101.dll
not found 2020-01-20 12:27:44.554964 : i
tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart
dlerror if you do not have a GPU set up on your machine.
如果你的機器上沒有CUDA
GPU,或者你不關心GPU加速,那麼無需擔心,如果安裝了Tensorflow並想要GPU加速,請檢查CUDA安裝(TF 2.1需要CUDA
10.1)。如果只想刪除警告,你可以調整TF的日誌記錄級別來禁止顯示警告,但是有缺點,因為它會關閉所有警告。Tensorflow 1.X或2.0:your CUDA setup is broken, ensure you have the correct version installed. (你的CUDA設置已損壞,請確保安裝了正確的版本。)