简体   繁体   中英

using Tensorflow with Anaconda and PyCharm on Windows

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.

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.

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.

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, ie ~/.virtualenvs/myenv/bin/python or ~/.virtaulenvs/myenv/usr/bin/python

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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