4

when I tried to build with python in ST3, I get an import error as I tried to do

import caffe

but when I simply ran on the terminal, typing

$ python
>>> import caffe

it works. On my sublime text 3 I still can import other modules like numpy and matplotlib.

This is the sublime python build I found (is this the right location? Why is it not extracted out but instead in a package?): The directory is: /opt/sublime_text/Packages/Python.sublime-package

and the file python.sublime-build in the Python.sublime-package is:

{
    "shell_cmd": "python -u \"$file\"",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",

    "env": {"PYTHONIOENCODING": "utf-8"},

    "variants":
    [
        {
            "name": "Syntax Check",
            "shell_cmd": "python -m py_compile \"${file}\"",
        }
    ]
}

After I checked my python path:

$ python -c "import sys; print '\n'.join(sys.path)"

my output is:

/home/user/caffe/python
/home/user
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/PILcompat
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/python2.7/dist-packages/wx-3.0-gtk2

and my dist-packages doesn't have caffe as I installed it in home/user instead.

So I decided to run in the terminal:

export PYTHONPATH=/home/user/caffe/python:$PYTHONPATH

but checking my python path again, it doesn't seem to get added in. Is this the reason? However, why is it that I can import caffe directly from my terminal but not in ST3? PS: I did add caffe to my user and etc bashrc profile.

Thank you for your help.

kwotsin
  • 2,882
  • 9
  • 35
  • 62
  • Possible duplicate of [Sublime Text2 Import error: No module named Gnuplot](http://stackoverflow.com/questions/13239839/sublime-text2-import-error-no-module-named-gnuplot) – idleberg Aug 20 '16 at 08:53

2 Answers2

1

You can add this before import caffe

import sys
sys.path.insert(0, '/path_to_caffe_root/python')
iparjono
  • 361
  • 1
  • 2
  • 9
  • After I added the command, I could not import the dependencies required in caffe, like libcudart.so.8.0. What is the fundamental cause of why ST3 couldn't import caffe, although my terminal could? Is there a way to target this problem directly? – kwotsin Aug 20 '16 at 03:59
  • what about putting 1 instead of 0 for the first argument? – iparjono Aug 20 '16 at 04:04
  • hmm it gives the same problem as putting 0. – kwotsin Aug 20 '16 at 04:04
  • well, what about using `append`? – iparjono Aug 20 '16 at 04:12
  • for append, I removed the number as it takes in only 1 argument. However, it gives the same error as before. – kwotsin Aug 20 '16 at 04:13
  • Can you show the error? What did you mean by importing dependencies? – iparjono Aug 20 '16 at 06:02
  • Anyway, it might be caused by the order of paths to see first. There are discussions about this, might be useful for you (http://stackoverflow.com/questions/10095037/why-use-sys-path-appendpath-instead-of-sys-path-insert1-path) and (http://stackoverflow.com/questions/1893598/pythonpath-vs-sys-path) – iparjono Aug 20 '16 at 06:12
0

I had the same problem. It turned out that there were a few virtual environments on my computer, because of Anaconda. I deactivated the virtual environmet, command pip3 list didn't show the required package, so it was installed and ST stopped complaining.

I caused the mess, without knowing -- some packages were installed in the virtual environment, and some not.

khaz
  • 369
  • 3
  • 12