sublime怎么导入python_Sublime Text 3无法导入python模块,但可以从命令行导入吗?

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.

解决方案

You can add this before import caffe

import sys

sys.path.insert(0, '/path_to_caffe_root/python')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值