0

I want to use pycurl with ST3 for one of my plugin which am creating.

I installed pycurl using pip3 install pycurl and I can get it working on python console but when I use import pycurl in my ST3 plugin it throws error ImportError: No module named 'pycurl'

I found this post and it suggested to move the module code inside package directory and I did the same.

Here is my package structure

MyPackage-Dir
 >> MyPackage.py
 >> lib
    >> pycurl
      >> complete module contents

I git cloned pycurl repo and placed its content inside the above pycurl folder. After this I changed my code reference to from .lib import pycurl but am getting error AttributeError: 'module' object has no attribute 'Curl' when I try to use c = pycurl.Curl()

So, any ideas on how to correctly reference 3rd party libs in ST3

PS : I am on OS X El Capitan 10.11.1 & I installed python2 & python3 without using brew or any package manager

Community
  • 1
  • 1
RanRag
  • 48,359
  • 38
  • 114
  • 167
  • Usually when I have an issue like this, it is because Sublime Text is using an alternate version of Python that indeed does not have the specific package I am trying to use installed in it. If you have more than one version of Python installed, be sure that Sublime Text is using the correct version that you installed `pycurl` to. – jesterjunk Dec 28 '15 at 10:30
  • @jesterjunk : I am using ST3 and as per my understanding it uses `python 3.3` and my current system version of python is `python 3.5`. So, can this be a reason? – RanRag Dec 28 '15 at 10:34
  • what output do you get if you execute `print(dir(pycurl))` in your plugin, on the line just before the error occurs? – Keith Hall Dec 29 '15 at 10:01
  • @KeithHall : This is what I get in ST3 console `['__doc__', '__initializing__', '__loader__', '__name__', '__package__', '__path__'] ` when I do `dir(pycurl)`. I see that pycurl is not a pure python module it seems to be a C module and also just to re-state again I just copied the folder content, I didn't perform any install like `setup.py install` on the git cloned code. – RanRag Dec 29 '15 at 16:12

1 Answers1

0

Sublime Text 3 uses an internal version of Python (3.3.3) that is compiled into the binary itself. Therefore, you can't use pip to install extensions for it. Additionally, pycurl has some compiled C extensions, so in order to use it in your plugin you'll have to compile it against Python 3.3.3 on each platform you want your plugin to work on. Simply cloning the git repo into your plugin directory won't work.

So, assuming you already have XCode, the command line tools, and libcurl installed on your system, download the 3.3.3 .dmg installer from python.org and install it. Next, download the latest pycurl release, extract the archive, change to its directory, and run

/Library/Frameworks/Python.framework/Versions/3.3/bin/python3 setup.py build

The complete installation instructions are here. Once it has built successfully, you should be able to copy the contents of the build/temp.macosx... directory to your plugin's lib directory.


However, I think you should be asking yourself "Can I do this a different way?" I would strongly recommend taking a look at the pure-Python requests library. It's fast, it's easy to use, and if you plan on distributing your plugin you don't need to worry about compiling platform-specific versions.

MattDMo
  • 100,794
  • 21
  • 241
  • 231