PyCharm 2019.1 has tensorflow but import doesn't work

I've installed tensorflow on PyCharm 2019.1, and it must be there because when I type "from tensorflow import k" I get a "keras" autocomplete option, as I would expect.

But when I try "import tensorflow as tf" and try to run, I get a "ImportError: No module named tensorflow" error.

I can successfully import the package from the console this way, just not in running an actual script. What might be going on here?

Thanks in advance.

 

4 comments
Comment actions Permalink

Hi,

That means that your script is being run from different environment for some reason. Ensure that your run configuration is set to use default project interpreter, the same that python console use.

 

Compare the output of `print(sys.path)` both from your script and python console.

0
Comment actions Permalink

And how do I change that? Why project creation isn't handling this setup correctly?

0
Comment actions Permalink

BTW, there is an open issue at tensorflow github on this issue, along with a workaround: https://github.com/tensorflow/models/issues/3655

0
Comment actions Permalink

Run this script from both PyCharm and command-line, and provide the outputs (preferably in two text files, please don't copy-paste it in the reply)

https://gist.github.com/vlasovskikh/968240f877117cb6c882#gistcomment-2230845

0

Please sign in to leave a comment.