简体   繁体   中英

Using Tensorflow as environment of Anaconda

I've installed anaconda (python3.6) and installed tensorflow as mentioned here:

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. I've tried the same in Spyder with the same result.

 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.

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:

import tensorflow as tf

To make things work in SublimeText editor, please follow the steps as documented here: sublimeText and 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.

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

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