简体   繁体   English

在pyCharm上使用tensorflow

[英]use tensorflow on pyCharm

I am new to Deep Learning and I have just installed tensorflow on my Mac, however, there are some problems. 我是Deep Learning的新手,我刚刚在我的Mac上安装了tensorflow,但是,有一些问题。

I am sure I installed successfully because I can run tensorflow on Terminal using python 3.5 我确信我安装成功,因为我可以使用python 3.5在终端上运行tensorflow

import tensorflow as tf  
node1 = tf.constant(3.0, tf.float32)  
node2 = tf.constant(4.0)  # also tf.float32 implicitly  
print(node1, node2)  

there is an output on my bash 我的bash上有一个输出

Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)

However, when I run import tensorflow as tf on Python Console of PyCharm. 但是,当我在PyCharm的Python控制台上运行import tensorflow as tf时。 A problem occurred: 出现问题:

>>> import tensorflow as tf
ImportError: No module named 'tensorflow'

I just went through this a few days ago after switching to PyCharm. 几天前,我在切换到PyCharm之后就完成了这个工作。 You have to select the right Project Interpreter so it can find the Python installation that includes Tensorflow. 您必须选择正确的Project Interpreter才能找到包含Tensorflow的Python安装。 In the menu go to PyCharm->Preferences and under the section Project: PyCharm on the left select Project Interpreter. 在菜单中转到PyCharm-> Preferences并在左侧的Project:PyCharm部分下选择Project Interpreter。 In my case, I select 3.5.2 (~/anaconda/bin/python) because there's where my Tensorflow seems to reside. 在我的情况下,我选择3.5.2(〜/ anaconda / bin / python),因为我的Tensorflow似乎就在那里。 Whatever versions you select, scroll through the window at the bottom to make sure you see Tensorflow listed as a Package. 无论选择何种版本,都可以滚动窗口底部的窗口,确保将Tensorflow列为一个包。

IMPORTANT: in my case it seems that once you OK this, it takes a while for PyCharm to digest? 重要提示:在我的情况下,似乎一旦你好了,PyCharm需要一段时间才能消化? Because for a while the 'Run' button is greyed out and you can't run your program. 因为有一段时间“运行”按钮显示为灰色,您无法运行程序。 Took me a while to figure what I'm doing wrong, but looks like you just need to give it sometime and it picks it up and the Run button goes back to green. 我花了一些时间来弄清楚我做错了什么,但看起来你只需要在某个时候给它并将它拿起并且Run按钮返回绿色。 Hope this works for you... 希望这对你有用......

I am using the Community Edition, for what it's worth... 我正在使用社区版,因为它的价值......

I'm using PyCharm 2018.1.4 Community Edition on Fedora 28, and have TensorFlow 1.9.0 installed (through "sudo pip3 install --upgrade tensorflow"). 我在Fedora 28上使用PyCharm 2018.1.4 Community Edition,并安装了TensorFlow 1.9.0(通过“sudo pip3 install --upgrade tensorflow”)。 Here is my step to load TensorFlow 这是我加载TensorFlow的步骤

File > Settings > Project > Project Interpreter > Change to "/usr/bin/python3.6" in Project Interpreter, then the installed Package will be loaded and displayed. 在Project Interpreter中将文件>设置>项目>项目解释器>更改为“/usr/bin/python3.6”,然后将加载并显示已安装的包。

Good luck. 祝好运。

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

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