Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top