You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL环境TensorFlow GPU可用时无法调用numpy等模块问题咨询

解决WSL2 TensorFlow GPU环境Jupyter依赖问题的方案

1. 锁定环境一致性

  • 打开WSL终端,激活TensorFlow GPU对应的虚拟环境:
    • Conda环境:conda activate tf-gpu
    • Venv环境:source ./tf-gpu-env/bin/activate
  • 查看当前环境Python路径:which python,记录该路径
  • 从激活的环境内启动Jupyter:jupyter notebook,避免系统默认Python内核干扰

2. 创建专属Jupyter内核

  • 激活目标环境后,安装内核依赖:pip install ipykernel
  • 注册专属内核:
    python -m ipykernel install --user --name tf-gpu-kernel --display-name "TensorFlow GPU (WSL2)"
    
  • 重启Jupyter,在内核选择菜单中切换到该专属内核,彻底隔离环境冲突

3. 修复GPU识别不稳定问题

  • 在WSL终端执行nvidia-smi,确认输出正常(显示GPU信息);若报错,重新安装Windows端的NVIDIA WSL驱动(无需在WSL内安装驱动)
  • 配置环境变量强制GPU调用:在终端配置文件(~/.bashrc或~/.zshrc)中添加:
    export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH
    export CUDA_VISIBLE_DEVICES=0
    
    执行source ~/.bashrc生效,每次启动环境自动加载

4. 重新安装依赖到目标环境

  • 激活TensorFlow GPU环境后,重装所有需要的依赖:
    pip install numpy scikit-learn matplotlib jupyter
    
  • 切换到专属内核后,执行import numpy, sklearn, matplotlib验证依赖,同时用tf.config.list_physical_devices('GPU')确认GPU识别状态

5. 排查环境冲突

  • 检查多Python版本干扰:whereis python,确保Jupyter使用的是目标环境的Python路径
  • 清理pip缓存:pip cache purge,重新安装依赖避免缓存损坏

内容的提问来源于stack exchange,提问作者U. U

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 09:49:53