我正在编写一个sublime text 2插件,它使用一个模块SEAPI.py,该模块本身导入requests module。
由于sublime text 2使用自己的嵌入式python解释器,所以在我的ubuntu机器上看不到安装的requests模块(我得到以下错误:ImportError:No module named requests)。
到目前为止,我能找到的最佳解决方案是将'requests'模块(文件的整个目录)从/usr/lib/python2.7/dist-packages/requests复制到sublime text packages目录下的插件目录中。
但在那之后,它说它找不到“urllib3”模块。
有没有更好的方法来导入请求模块,这样我就不必将所有文件复制到我的插件目录中?
我现在使用的代码如下:
MyPlugin.pyimport sublime
import sublime_plugin
import SEAPI
...
西皮.pyimport requests
try:
import simplejson as json
except:
import json
from time import time, sleep
...
编辑:
所选的答案是正确的,并修复了我的主要问题,但使用当前版本的“请求”和嵌入的sublime text 2解释器存在不同的问题。ST2的python缺少常规2.7 python中存在的各种模块(如“fileio”)。
我不得不将“urllib3/response.py”文件编辑为:try:
from cStringIO import StringIO as BytesIO
except ImportError:
pass # _fileio doesn't seem to exist in ST's python in Linux, but we don't need it