14
votes

I am using Anaconda 4.3.1 64 Bit on Windows 10 64 Bit. I have successfully installed Tensorflow (CPU) according to this. The test program runs in the command line, but not in PyCharm. The problem is that it works only with activate tensorflow.

I followed the steps from Pycharm anaconda import tensor flow library issue ("You need to do these following steps:"). It seems now that tensorflow is loaded, but I get a new error:

ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.

How can I use TensorFlow in PyCharm? (BTW: Tensorflow works with PyCharm on my Fedora VM.)

Edit:

Can I use TensorFlow with Jupyter? When running "Jupyter (tensorflow)" from the Anaconda menu, a console window opens and immediately closes.

4

4 Answers

11
votes

When PyCharm is open: if you navigate to preferences: Project: Project Interpreter. You can there either create your own virtualenv (and then manually install the required packages) or make sure you have selected the anaconda python interpreter for your project.

5
votes

If following official instructions, you have created a virtual environment called tensorflow. The environment is located in Anaconda3\envs\tensorflow directory, where Anaconda3 is the Anaconda installation directory. You just need to point PyCharm to the python.exe which is located there.

The settings path in PyCharm is something like this:

Settings->Project Interpreter->Add Local->Virtualenv Environment->Existing environment

Point the interpreter to the python.exe in the Anaconda3\envs\tensorflow directory.

3
votes

I recommend installing babun and creating a virtualenv with virtualenvwrapper there and install on that environment.

After doing this, just choose the python binary in the relevant directory of the virtualenv you created, i.e. ~/.virtualenvs/myenv/bin/python or ~/.virtaulenvs/myenv/usr/bin/python

2
votes

Before importing anything else, do this

import sys
print(sys.path)

import os
print(os.environ)
print(os.environ['CUDA_VISIBLE_DEVICES'])

from the command line (when TF works) and from PyCharm (when it doesn't). If you see any relevant differences, adjust accordingly (define the environment variables in PyCharm, etc.)