14

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.

user495236
  • 241
  • 1
  • 3
  • 10

4 Answers4

11

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.

PdevG
  • 3,427
  • 15
  • 30
  • Can you elaborate a bit? What settings do I have to use for the creation of my virtualenv? The Anaconda Python interpreter is already selected. – user495236 May 26 '17 at 12:37
  • For the virtualenv I would use whatever interpreter you have that works best. This probably is anaconda. Then you give it a name (I mostly choose a name similar to my project). Afterwards in the same menu (Project Interpreter) you see a list of packages you have installed. If you want to install TensorFlow you click on the + in the bottom left and select tensorflow. Press install package and it should work. If you have any missing dependencies you can install them the same way. – PdevG May 26 '17 at 13:11
  • As a side note, you should run your files in this virtualenv for this to work. This is done automatically if you run your scripts using pycharm. If you insist on running your scripts from the command line you need to first mount your virtualenv. When you have the virtualenv wrapper installed this is as easy as typing: "workon " afterwards you can run your script. – PdevG May 26 '17 at 13:13
  • Thank you. When adding TensorFlow, I get the error "Collecting tensorflow==1.1.0rc2 Could not find a version that satisfies the requirement tensorflow==1.1.0rc2 (from versions: ) No matching distribution found for tensorflow==1.1.0rc2" (The same for the other versions of tensorflow.) – user495236 May 26 '17 at 15:19
  • That is superweird. It seems to be an issue with this particular package then. https://stackoverflow.com/questions/38896424/tensorflow-not-found-in-pip seems to offer a few solution. You can try those. Hope you can get it figured out! – PdevG May 28 '17 at 14:33
5

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.

klimkin
  • 573
  • 5
  • 10
3

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

onur güngör
  • 715
  • 5
  • 18
  • How do I create a `virtualenv` with `virtualenvwrapper`? What shall I install on this environment? – user495236 May 26 '17 at 07:05
  • Check https://github.com/babun/babun/issues/147 for that, and also did you follow https://www.tensorflow.org/install/install_windows ? – onur güngör May 27 '17 at 07:42
2

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.)

MWB
  • 11,740
  • 6
  • 46
  • 91