简体   繁体   English

使用Tensorflow作为Anaconda的环境

[英]Using Tensorflow as environment of Anaconda

I've installed anaconda (python3.6) and installed tensorflow as mentioned here: 我安装了anaconda(python3.6)并安装了tensorflow,如下所述:

conda create -n tensorflow python=3.5

and activated tensorflow, now I want to run example codes in sublime text3 and I can't import tensorflow. 并激活tensorflow,现在我想在sublime text3中运行示例代码,我无法导入tensorflow。 I've tried the same in Spyder with the same result. 我在Spyder尝试过相同的结果。

 import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

any idea what I'm doing wrong here? 知道我在这里做错了什么吗? (the code is definitely correct) (代码绝对正确)

What you are doing here is creating a virtual environment named tensorflow. 你在这里做的是创建一个名为tensorflow的虚拟环境。

The correct way to do it is: (in the same order) 正确的方法是:(以相同的顺序)

$ conda create --name yourenv python=3.5 anaconda
$ source activate yourenv
$ conda install -n yourenv tensorflow

Then, from the ipython terminal do: 然后,从ipython终端做:

import tensorflow as tf

To make things work in SublimeText editor, please follow the steps as documented here: sublimeText and VirtualEnv 要在SublimeText编辑器中使用,请按照此处记录的步骤操作: sublimeText和VirtualEnv

Basically, you need to add the following line in the project settings. 基本上,您需要在项目设置中添加以下行。

"settings": {
    "python_interpreter": "/home/user/.virtualenvs/example/bin/python"
}

For people using Anaconda distribution, it's little bit different. 对于使用Anaconda发行版的人来说,它有点不同。

"settings": {
        "python_interpreter": "/home/user/anaconda3/envs/myenv/bin/python"
    }

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

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