本文介绍了无法在Jupyter Notebook中导入Tensorflow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在conda环境中的Jupyter笔记本中导入Tensorflow模块,但出现以下错误:

I'm trying to import the Tensorflow module in my Jupyter notebook in a conda environment, but I get the following error:

AttributeError: type object 'h5py.h5.H5PYConfig' has no attribute '__reduce_cython__'

但是,如果我打开Anaconda Prompt,激活相同的环境并在shell中导入tensorflow,它确实可以工作.

However, if I open Anaconda Prompt, activate the same enviroment and import tensorflow in the shell, it does work.

版本:

  • tensorflow-gpu: 2.2
  • h5py: 2.10
  • tensorflow-gpu: 2.2
  • h5py: 2.10

我尝试降级到不同版本(h5py 2.7tf-gpu 2.1),但是这导致了软件包版本冲突的更多错误.

I tried downgrading to different versions (h5py 2.7 and tf-gpu 2.1), but that resulted in a lot more errors of conflicting versions of packages.

有人知道为什么Jupyter不加载该模块以及为什么它在Anaconda shell中工作吗?

Does anyone have an idea why Jupyter is not loading the module and why it is working within the Anaconda shell?

谢谢

推荐答案

您的jupyter笔记本可能正在基本环境中运行.如果jupyter笔记本安装在基本版本中但未安装在当前环境中,则可能会发生这种情况.

Your jupyter notebook is probably running from the base environment. This can happen if jupyter notebook is installed in base but not in your current env.

使用anaconda-navigator打开Anaconda Navigator,导航到环境"并激活您的环境,导航到主页"并安装jupyter笔记本,然后从导航器中使用午餐jupyter笔记本.

Open Anaconda Navigator with anaconda-navigator, navigate to Environments and active your env, navigate to Home and install jupyter notebook, then lunch jupyter notebook from the navigator.

首次执行此操作后,您可以执行以下操作:

After doing this for the first time, you can just do:

source activate your_env
jupyter-notebook

下次

这篇关于无法在Jupyter Notebook中导入Tensorflow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 10:11