简体   繁体   English

可以在python 3.4中导入tensorflow但不能在ipython笔记本中导入

[英]can import tensorflow in python 3.4 but not in ipython notebook

I have been running in circles trying to get tensorflow to work in a jupyter notebook. 我一直在圈子里奔波,试图让tensorflow在jupyter笔记本中工作。 I installed it via pip on ubuntu and also tried a conda environment (but unless I'm mistaken, getting that to work with ipython is beyond my ability). 我是通过ubuntu上的pip安装它的,还尝试了一个conda环境(但是除非我弄错了,否则我无法使用ipython来工作)。 Tensorflow works fine in python3.4, but not python 3.5, which is used when I load ipython. Tensorflow在python3.4中可以正常工作,但在加载ipython时使用的python 3.5不能正常工作。 I'm not sure if this question makes any sense, but can I make it so that ipython uses only python 3.4? 我不确定这个问题是否有意义,但是我可以做到这一点,以便ipython仅使用python 3.4吗? The reason I need to use ipython instead of going through the python shell is that I am trying to use the kadenzie tutorial. 我需要使用ipython而不是通过python shell的原因是我正在尝试使用kadenzie教程。

Thank you. 谢谢。

Edit: I'm not sure how applicable this is to other people with my problem, but I solved it by changing my conda python version (conda install python=3.4.3), uninstalling ipython, and then reinstalling it. 编辑:我不确定这对我的问题是否适用,但是我通过更改conda python版本(conda install python = 3.4.3),卸载ipython,然后重新安装解决了该问题。

Each major version of python has its own site-packages directory. python的每个主要版本都有其自己的site-packages目录。 It seems that you have both python 3.4 and 3.5 and you have jupyter installed in 3.5 and tensorflow in 3.4. 似乎您同时拥有python 3.4和3.5,并且在3.5中安装了jupyter,在3.4中安装了tensorflow。 The easy solution is to install tensorflow in 3.5 as well. 简单的解决方案是在3.5中也安装tensorflow。 This should allow you to use it with the 3.5 notebook kernel. 这应该允许您将其与3.5笔记本内核一起使用。 You could attempt to add 3.4 as a kernel, but I am not sure how to do that. 您可以尝试将3.4添加为内核,但是我不确定该怎么做。

The best way to setup tensorflow with jupyter 1.Install anaconda 2.Create a environment named "tensorflow" 3.activate that environment by the following command in command prompt 用jupyter设置tensorflow的最佳方法1.安装anaconda 2.创建一个名为“ tensorflow”的环境3.在命令提示符下通过以下命令激活该环境

  • Install anaconda 安装水蟒
  • Create a environment named "Tensorflow" 创建一个名为“ Tensorflow”的环境
  • activate that environment by the following command in command prompt 通过命令提示符中的以下命令激活该环境

    activate tensorflow 激活张量流

  • then type conda install ipykernel 然后键入conda install ipykernel

  • then when it is installed paste the following command 然后在安装时粘贴以下命令

    python -m ipykernel install --user --name myenv --display-name "Python[Tensorflow]" python -m ipykernel install --user --name myenv --display-name“ Python [Tensorflow]”

Then run jupyter notebook in command prompt 然后在命令提示符下运行jupyter notebook

after that when you are going to create a new notebook you will see two types of notebook just select the tensorflow one. 之后,当您要创建一个新笔记本时,您将看到两种类型的笔记本,只需选择tensorflow。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM