3

I'm trying to run a script that begins:

from pycurl import *

However, this throws the error:

Traceback (most recent call last):
  File "/Users/adamg/PycharmProjects/untitled/UrlToText.py", line 1, in <module>
    from pycurl import *
ImportError: dlopen(/Users/adamg/anaconda/lib/python2.7/site-packages/pycurl.so, 2): Library not loaded: libcurl.4.dylib
  Referenced from: /Users/adamg/anaconda/lib/python2.7/site-packages/pycurl.so
  Reason: Incompatible library version: pycurl.so requires version 8.0.0 or later, but libcurl.4.dylib provides version 7.0.0

I'm trying to understand this error, and exactly what needs to be done to correct it. I'm using PyCharm v 3.1.

Adam_G
  • 7,337
  • 20
  • 86
  • 148

1 Answers1

2

It looks like you need to install an updated version of curl. Based on your /Users/... path it looks like you're on a mac (but you should probably include that explicitly in the question). Macs ship with old versions of curl.

I just tried installing pycurl on Mac OS X 10.9.2, then opening a python shell and

>>> from pycurl import *

And this worked. I have a fresh install, not an upgrade, of Mavericks. If you upgraded to Mavericks, this might be why you have an old version of libcurl. If this doesn't work in the python shell, chances are you have an old version of libcurl.4.dylib and very likely this has nothing to do with pycharm.

To get an updated version run

$ brew install curl

The next part is a bit of a hack and not the "right" way to do it, but I have a feeling it will work, and this is the simplest way to try to get something working.

Just copy libcurl.4.dylib that brew has grabbed and put it in /usr/lib after making a copy of it so you can put it back if this doesn't work:

$ sudo cp /usr/lib/libcurl.4.dylib /usr/lib/libcurl.4.dylib.bk
$ sudo cp /usr/local/opt/curl/lib/libcurl.4.dylib /usr/lib/libcurl.4.dylib

Try running curl from the command line, something dumb like curl www.google.com. If it still works, then curl still works, and we're good.

Now try to run your script again. Hopefully it finds this updated libcurl.4.dylib and imports successfully. If it still doesn't work, try uninstalling and re-installing pycurl.

Matthew Turner
  • 3,564
  • 2
  • 20
  • 21
  • Thanks. This didn't seem to resolve the issue, though. Unfortunately the linked answer didn't help, either. – Adam_G Apr 15 '14 at 17:28
  • Did you restart the shell you were working in? Do you get the same error? I'm not sure why, but sometimes after installing I've even had to restart, or at least log out and log back in. Also, what version of OS X are you on? – Matthew Turner Apr 15 '14 at 18:57
  • Tried restarting my machine, but still the same error. I'm running OSX 10.9.2 – Adam_G Apr 15 '14 at 21:21
  • hmm... I'd say it's definitely something related to pycurl not being able to find the updated dynamic library. But it's hard to know without more info. Did you install pycurl yourself or did it come with your python install? I would also try removing and re-installing pycurl (e.g. using `pip`). If pip still doesn't work I'd try following these [instructions](http://pycurl.sourceforge.net/doc/install.html). – Matthew Turner Apr 15 '14 at 21:56
  • 1
    What information can I provide you that would help? I'm really desperate to figure this out. I think it has to do with where I installed pycurl, and where pycharm is looking. How do I find that and then change that? – Adam_G Apr 16 '14 at 19:45
  • I'm not too familiar with pycharm, but it's just an editor, right? If so, I wouldn't think it has anything to do with pycharm. Here's something to try to be sure about it: open a terminal and start the python interpreter. Then try `from pycurl import *`. If it still doesn't work then it's probably not a pycharm issue. I'm going to update my answer with something that might be a little more helpful. I see now that the link is actually unrelated, sorry about that. – Matthew Turner Apr 16 '14 at 21:53
  • Well, this got it working in IDLE (but not PyCharm), but I don't care. So, first off, thank you! The only issue I have now is that the original script `pycurl` is meant for (http://stackoverflow.com/questions/22766283/gathering-formatted-content-from-multiple-webpages) isn't working as expected. If you know how to solve that, I'd be glad to offer you a bounty. – Adam_G Apr 17 '14 at 02:11
  • This didn't work for me ... ie I am still getting `Reason: Incompatible library version: pycurl.so requires version 8.0.0 or later, but libcurl.4.dylib provides version 7.0.0` despite doing a brew update. Am using yosemite – Ammar Akhtar Jan 09 '15 at 20:24