windows10+gpu版本的tensorflow全过程

搞了三天,踩坑无数,终于搞定了。
经验1:一定要版本对应 tensorflow-gpu、CUDA、cuDNN
经验2:装在windows上的话,较高版本/较新版本的上面三个不支持!

1.新建环境 conda create -n gpu_env python=3.7 (一开始搞了3.8以上!!!千万不要,因为python3.8对应的tensorflow-gpu并不能用在windows上,在一个网页看到的这句话,后面有截图)

2.激活环境conda activate gpu_env(gpu_env是环境名)

3.安装tensorflow-gpu pip install -i https://pypi.mirrors.ustc.edu.cn/simple tensorflow-gpu==2.6.0 (后面的镜像源可以换,阿里云、豆瓣的似乎更好用一些,看到一些帖子说清华的会不稳定。在这里踩到的坑很多,比如显示安装失败、一直salving environment;需要注意的是,要先装tensorflow-gpu!另外,最重要的是,不能超过2.11!!)

4.下载jupyter notebook pip install Jupyter -i https://pypi.doubanio.com/simple (尝试了不用镜像–显示失败or一直安装中;尝试在anaconda里install,一直不成功;尝试在VScode里装,一直不成功;最后用这个带镜像的,成功~)

5.安装CUDA工具包 我的是11.2版本(先用nvidia-smi查看自己设备能使用的CUDA的最高版本,这里显示的是12.2,只要低于它即可)
在这里插入图片描述
6.安装cuDAA库 我的是8.1版本(要版本对应) (在这里看到了那句windows不支持2.11以上的tensorflow-gpu!!!!)
在这里插入图片描述
7.验证GPU是否可用 (返回true表明gpu版本的tensorflow可用;如果显示false,说明tensorflow-gpu或CUDA或cuDNN有版本错误;后面的GPUS为1说明只有一个GPU设备)
在这里插入图片描述
完成!

中间遇到的问题及解决方案:

问题1:新建环境时报错:CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64/current_repodata.json
法1:在anaconda prompt执行以下命令
conda config --add channels - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
然后在“C:\Users\Administrator(你的用户名)”目录下找到“.condarc”文件并打开,若channels下面有-default,删除-default,保存退出,重新新建环境
法二:将“.condarc”文件中的https改成http将“.condarc”文件中的https改成http
法三:离线创建:conda config --set offline true,重新新建环境
(盲猜,以后遇到报错httperror/与网络相关的问题时,都用第三种方式解决)

问题2:安装gpu-tensorflow时,报错:
tensorboard 2.11.2 has requirement protobuf<4,>=3.9.2, but you’ll have protobuf 4.24.4 which is incompatible.
法一:pip install --upgrade tensorboard (这个方法不可取,因为改变它的板本就和tensorflow的不对应了)
法二:pip install protobuf==3.9.2

问题3:you are using pip version 10.0.1,however version 23.3.1 is available
法一:不要直接win+R然后cmd,而是要选择“开始”—“Windows系统”—“命令提示符”—右键“以管理员身份运行”;不要用家用WiFi,开手机热点连接;管理员身份运行命令提示符后,使用镜像下载升级,代码如下:python -m pip install --upgrade pip -i https://pypi.douban.com/simple

问题4:安装gpu-tensorflow时,报错:ERROR: Cannot uninstall ‘wrapt’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
法一:更新一系列包:pip install -U --ignore-installed wrapt enum34 simplejson netaddr,在重新安装(没用,报错)
法二:手动卸载电脑中所有有关wrapt的文件,然后重新安装

问题5:
DEPRECATION: pandas 0.23.4 has a non-standard dependency specifier pytz>=2011k. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of pandas or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063
法一:pip install --upgrade pandas -i https://pypi.doubanio.com/simple/

问题6:安装gpu-tensorflow时,报错: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-intel 2.11.0 requires libclang>=13.0.0, which is not installed.
tensorflow-intel 2.11.0 requires packaging, which is not installed.
tensorflow-intel 2.11.0 requires tensorflow-io-gcs-filesystem>=0.23.1; platform_machine != “arm64” or platform_system != “Darwin”, which is not installed.
tensorflow-intel 2.11.0 requires absl-py>=1.0.0, but you have absl-py 0.15.0 which is incompatible.
tensorflow-intel 2.11.0 requires flatbuffers>=2.0, but you have flatbuffers 1.12 which is incompatible.
tensorflow-intel 2.11.0 requires numpy>=1.20, but you have numpy 1.19.5 which is incompatible.
解决:尝试先卸载它,以避免版本冲突。python -m pip uninstall tensorflow-intel
然后重新下载tensorflow-gpu

### 升级 Pandas 以解决 Pytz 版本依赖问题 Pandas 的正常运行确实需要一些依赖库的支持,其中包括 `pytz` 和其他核心 Python 库。如果遇到因 `pytz` 版本不满足要求而导致的错误,可以通过以下方法解决问题。 #### 方法一:更新所有相关依赖 可以尝试通过 `pip` 更新所有的依赖项到最新版本。这通常能够解决由于旧版依赖引起的兼容性问题。 ```bash pip install --upgrade pandas pytz numpy ``` 此命令会自动检测并安装最新的 `pandas` 及其所需的所有依赖项[^1]。 #### 方法二:指定特定版本的 Pytz 如果当前环境中存在多个版本冲突的情况,则可以直接指定所需的最低版本号来安装 `pytz`: ```bash pip install pytz>=2017.2 ``` 这里选择了较新的稳定版本 (如 `2017.2`) 来替代过时的 `2011k`,从而减少潜在的风险[^2]。 #### 方法三:创建独立虚拟环境重新构建项目生态链 当本地全局环境下难以调整各包之间的关系时,建议新建一个隔离的工作区来进行操作。这样不仅可以保护原有配置不受影响,还能更灵活地管理各个项目的个性化需求。 ```bash # 创建新虚拟env python -m venv my_pandas_env # 激活该venv source my_pandas_env/bin/activate # Linux/MacOS 或者 Windows 下使用my_pandas_env\Scripts\activate.bat # 安装必要的组件 pip install pandas pytz numpy scipy matplotlib seaborn jupyterlab etc. ``` 以上步骤有助于建立纯净且一致性的开发平台[^3]。 #### 注意事项 - 如果仍然无法成功导入模块,请仔细核对拼写是否正确。“import pandas” 是官方推荐的形式,“import pands” 属于笔误情况下的非法调用[^4]。 - 对于某些特殊场景比如跨操作系统移植或者硬件资源受限条件下部署应用实例时,可能还需要额外考虑更多因素诸如编译器支持状况、目标架构匹配度等问题。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值