using Tensorflow with Anaconda and PyCharm on Wind

2020-07-03 07:56发布

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条回答
时光不老,我们不散
2楼-- · 2020-07-03 08:14

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.

查看更多
欢心
3楼-- · 2020-07-03 08:33

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.

查看更多
闹够了就滚
4楼-- · 2020-07-03 08:34

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

查看更多
甜甜的少女心
5楼-- · 2020-07-03 08:41

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

查看更多
登录 后发表回答