Python 在 Windows 上使用 Tensorflow 与 Anaconda 和 PyCharm
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44059934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
using Tensorflow with Anaconda and PyCharm on Windows
提问by user495236
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 commandline, but not in PyCharm. The problem is that it works only with activate tensorflow.
我在 Windows 10 64 位上使用 Anaconda 4.3.1 64 位。我已经根据this成功安装了Tensorflow(CPU)。测试程序在命令行中运行,但不在PyCharm 中。问题是它只适用于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:
我按照Pycharm anaconda 导入张量流库问题中的步骤操作(“您需要执行以下步骤:”)。现在似乎已加载 tensorflow,但我收到一个新错误:
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.
导入错误:导入多阵列 numpy 扩展模块失败。很可能您正在尝试导入失败的 numpy 构建。如果您正在使用 numpy git repo,请尝试
git clean -xdf
(删除所有不受版本控制的文件)。否则重新安装numpy。
How can I use TensorFlow in PyCharm? (BTW: Tensorflow works with PyCharm on my Fedora VM.)
如何在 PyCharm 中使用 TensorFlow?(顺便说一句:Tensorflow 在我的 Fedora VM 上与 PyCharm 一起工作。)
Edit:
编辑:
Can I use TensorFlow with Jupyter? When running "Jupyter (tensorflow)" from the Anaconda menu, a console window opens and immediately closes.
我可以将 TensorFlow 与 Jupyter 一起使用吗?从 Anaconda 菜单运行“Jupyter (tensorflow)”时,控制台窗口会打开并立即关闭。
采纳答案by PdevG
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.
当 PyCharm 打开时:如果您导航到首选项:项目:项目解释器。您可以在那里创建自己的 virtualenv(然后手动安装所需的包)或确保您已为您的项目选择了 anaconda python 解释器。
回答by klimkin
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.
如果遵循官方说明,您已经创建了一个名为tensorflow的虚拟环境。环境位于Anaconda3\envs\tensorflow
目录中,其中Anaconda3
是Anaconda的安装目录。您只需要将 PyCharm 指向python.exe
位于那里的 。
The settings path in PyCharm is something like this:
PyCharm 中的设置路径是这样的:
Settings->Project Interpreter->Add Local->Virtualenv Environment->Existing environment
Settings->Project Interpreter->Add Local->Virtualenv Environment->Existing environment
Point the interpreter to the python.exe
in the Anaconda3\envs\tensorflow
directory.
点解释到python.exe
在Anaconda3\envs\tensorflow
目录中。
回答by onur güng?r
I recommend installing babun
and creating a virtualenv
with virtualenvwrapper
there and install on that environment.
我建议在那里安装babun
和创建一个并安装在该环境中。virtualenv
virtualenvwrapper
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
这样做后,只需python
在您创建的virtualenv的相关目录中选择二进制文件,即~/.virtualenvs/myenv/bin/python
或~/.virtaulenvs/myenv/usr/bin/python
回答by MaxB
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.)
从命令行(当 TF 工作时)和来自 PyCharm(当它不工作时)。如果您看到任何相关差异,请相应调整(在 PyCharm 中定义环境变量等)