问题
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:
You can add this before import caffe
import sys
sys.path.insert(0, '/path_to_caffe_root/python')
来源:https://stackoverflow.com/questions/39050042/sublime-text-3-unable-to-import-python-module-although-importing-from-command-li