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.

1

2 Answers 2

1

You can add this before import caffe

import sys
sys.path.insert(0, '/path_to_caffe_root/python')
Sign up to request clarification or add additional context in comments.

7 Comments

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?
what about putting 1 instead of 0 for the first argument?
hmm it gives the same problem as putting 0.
well, what about using append?
for append, I removed the number as it takes in only 1 argument. However, it gives the same error as before.
|
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.