【发布时间】:2013-02-17 07:12:27
【问题描述】:
我正在编写一个 sublime text 2 插件,它使用一个模块 SEAPI.py,该模块本身导入 requests module。
由于 sublime text 2 使用它自己的嵌入式 python 解释器,它没有看到我的 ubuntu 机器中安装的 requests 模块(我收到以下错误:ImportError: No module named requests)。
到目前为止,我能找到的最佳解决方案是将“请求”模块(文件的整个目录)从 /usr/lib/python2.7/dist-packages/requests 复制到 sublime 文本包目录中的插件目录中. 但在那之后,它说它找不到'urllib3'模块。
有没有更好的方法来导入 requests 模块,这样我就不必将所有文件复制到我的插件目录中?
我目前使用的代码如下:
MyPlugin.py
import sublime
import sublime_plugin
import SEAPI
...
SEAPI.py
import requests
try:
import simplejson as json
except:
import json
from time import time, sleep
...
编辑: 选择的答案是正确的,并且解决了我的主要问题,但是使用当前版本的“请求”和嵌入式 sublime text 2 解释器存在不同的问题。 ST2 的 python 缺少常规 2.7 python 中存在的各种模块(例如'fileio')。
我已经通过使用此处的“请求”模块解决了这个问题: https://github.com/bgreenlee/sublime-github
我不得不将 '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
【问题讨论】:
标签: python plugins sublimetext2 distutils python-requests