1

I am a new user of Sublime Text. I am have been spending times to figure out how to run my Python code which uses Tensorflow library. The terminal was thrown an error showing that "ImportError: No module named tensorflow". But I already installed Anaconda and tensorflow many weeks ago and it run pretty fine using Gedit. How to solve this issue?

Joshua
  • 409
  • 1
  • 4
  • 12

2 Answers2

3

I've been through this just now. See if this work for you:

  1. Make a new build system in Sublime Text:

    Tools > Build System > New Build System

This will open an file "untitled.sublime-build" waiting for you to fill in.

  1. Paste the following in that file and fix the path so that it points to the python executable in your own tensorflow environment under anaconda.

    {
        "cmd": ["/Users/yourUserName/anaconda3/envs/tensorflow/bin/python3", "-u", "$file"],
        "file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
        "selector": "source.python"}
    }
    
  2. Save that file with a descriptive name like "tf_conda.sublime-build"

  3. Now build your python script using this custom build system. Choose

    Tools > Build System > tf_conda

    and Ctrl + b to build and run your script.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
rljc
  • 31
  • 4
0

I had the same issue I solved it a little different. I am on Windows all I had to do was change the envierment variable to where where you installed Anaconda3 instead of any other python you may have installed separately.

I found this answear on another stackoverlow question. The one thing to mention in addition to this is that you need to move up the anaconda path and script path to the top two spots so that it ignores any other python you may have installed.

To me this is a better way to set up sublimeREPL as it works right out of the box with out adding any new builds. This also works best as if you decided to switch editions you would not have to change the path in that editor. Everything just works out of the box if I do it way. I have tried doing it other ways but then end up having other errors for other sublime packages. This is also great because if in the future you needed to use an older python it’s much easier to change it in one spot rather than changing the path individually in several editors or python IDE’s

This may vary on your pc but for me I my amaconda was installed on. C:\Anaconda3. Therefore you need to add C:\Anaconda3 as well as C:\Anaconda3\Scripts\ to your path variable, e.g. set PATH=%PATH%;C:\Anaconda3;C:\Anaconda3\Scripts.

You can do this via powershell (see above, https://msdn.microsoft.com/en-us/library/windows/desktop/bb776899(v=vs.85).aspx ), or hit the windows key -> enter environment -> choose from settings -> edit environment variables for your account -> select Path variable -> Edit -> New.

Link here if you want to read the whole post. conda command is not recognized on windows 10

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135