简体   繁体   English

在Windows上使用Tensorflow和Anaconda和PyCharm

[英]using Tensorflow with Anaconda and PyCharm on Windows

I am using Anaconda 4.3.1 64 Bit on Windows 10 64 Bit. 我在Windows 10 64位上使用Anaconda 4.3.1 64位。 I have successfully installed Tensorflow (CPU) according to this . 我照着成功安装Tensorflow(CPU) The test program runs in the command line, but not in PyCharm . 测试程序在命令行中运行,但不在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:"). 我按照Pycharm anaconda导入张量流库问题的步骤(“你需要执行以下步骤:”)。 It seems now that tensorflow is loaded, but I get a new error: 现在似乎已加载tensorflow,但我收到一个新错误:

ImportError: Importing the multiarray numpy extension module failed. ImportError:导入多阵列numpy扩展模块失败。 Most likely you are trying to import a failed build of numpy. 您很可能正在尝试导入失败的numpy版本。 If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). 如果您正在使用numpy git repo,请尝试git clean -xdf (删除所有不受版本控制的文件)。 Otherwise reinstall numpy. 否则重新安装numpy。

How can I use TensorFlow in PyCharm? 如何在PyCharm中使用TensorFlow? (BTW: Tensorflow works with PyCharm on my Fedora VM.) (顺便说一句:Tensorflow在我的Fedora VM上与PyCharm一起使用。)

Edit: 编辑:

Can I use TensorFlow with Jupyter? 我可以将TensorFlow与Jupyter一起使用吗? When running "Jupyter (tensorflow)" from the Anaconda menu, a console window opens and immediately closes. 从Anaconda菜单运行“Jupyter(tensorflow)”时,控制台窗口会打开并立即关闭。

When PyCharm is open: if you navigate to preferences: Project: Project Interpreter. 当PyCharm打开时:如果您导航到首选项: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. 您可以在那里创建自己的virtualenv(然后手动安装所需的包)或确保为项目选择了anaconda python解释器。

If following official instructions , you have created a virtual environment called tensorflow . 如果遵循官方说明 ,您已创建了名为tensorflow的虚拟环境。 The environment is located in Anaconda3\\envs\\tensorflow directory, where Anaconda3 is the Anaconda installation directory. 该环境位于Anaconda3\\envs\\tensorflow目录中,其中Anaconda3是Anaconda安装目录。 You just need to point PyCharm to the python.exe which is located there. 你只需要将PyCharm指向位于那里的python.exe

The settings path in PyCharm is something like this: PyCharm中的设置路径是这样的:

Settings->Project Interpreter->Add Local->Virtualenv Environment->Existing environment 设置 - >项目解释器 - >添加本地 - > Virtualenv环境 - >现有环境

Point the interpreter to the python.exe in the Anaconda3\\envs\\tensorflow directory. 将解释器指向Anaconda3\\envs\\tensorflow目录中的python.exe

I recommend installing babun and creating a virtualenv with virtualenvwrapper there and install on that environment. 我建议安装babun和创建virtualenvvirtualenvwrapper那里,安装在该环境。

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 执行此操作后,只需在您创建的virtualenv的相关目录中选择python二进制文件,即~/.virtualenvs/myenv/bin/python~/.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). 从命令行(当TF工作时)和从PyCharm(当它没有)时。 If you see any relevant differences, adjust accordingly (define the environment variables in PyCharm, etc.) 如果您看到任何相关差异,请相应调整(在PyCharm中定义环境变量等)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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