It's a steep learning curve trying to integrate Mathematica with Python's modules/library. I am using a Raspberry Pi 3 with Mathematica's Wolfram command line. I know little about both platforms (so clearly Wolfram's genius/strategy is working on me! - LoL...)

My objective: Run .py scripts from within Mathematica's scripts (.m):

Problem: It works fine from within the shell command line, but when using the mathematica - script option, I get this error:

File "/usr/local/lib/python2.7/dist-packages/httplib2-0.9.2-py2.7.egg/httplib2/__init__.py", line 930, in <module>
    class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
AttributeError: 'module' object has no attribute 'HTTPSConnection'

For some reason, Python invoked via Mathematica seems to load modules differently.

For example:

python -v output shows me that from the shell the SSL module:

import ssl # precompiled from /usr/lib/python2.7/ssl.pyc

Whereas from Mathematica, there is an additional line:

import ssl # precompiled from /usr/lib/python2.7/ssl.pyc
dlopen("/usr/lib/python2.7/lib-dynload/_ssl.arm-linux-gnueabihf.so", 2);

My scripts are simple: The Mathematica .m file is just:

dist-packages"]; txtResult =
 Import["!/usr/bin/python /home/pi/aprilbot.py", "Text"]

And aprilbot.py imports module pytumblr, a Tumblr API client and posts a text message:


import pytumblr

token_key = 'xyz'

client = pytumblr.TumblrRestClient(

blogname = 'ABC'

client.create_text(blogname, state="published", slug="testing-post", title="Testing", body = "my text post..")


I am stuck :-(.

  • 3
    $\begingroup$ "Rapberry pi 3..." - is that some hip-hop version of the hardware? $\endgroup$
    – ciao
    Apr 30 '16 at 23:33
  • 1
    $\begingroup$ Try evaluating SetEnvironment["LD_LIBRARY_PATH" -> ""] first. $\endgroup$
    – ilian
    May 1 '16 at 1:43
  • $\begingroup$ <b><i> It worked!<i><b> OMG..<br> A quick google reveals that its because LD_LIBRARY_PATH is given priority over /lib and /usr/lib. fab. you've totally won my appreciation. thank you @ilian. <br>Now, to win the stackexchange score, can you please answer <i>_why_<i> mathematica's LD_LIBRARY_PATH interferes with this and perhaps where I could read up more about the specifics? $\endgroup$
    – berrynice
    May 1 '16 at 6:21
  • $\begingroup$ ..that was a typo y'all! RaSpberry. $\endgroup$
    – berrynice
    May 1 '16 at 6:28
  • $\begingroup$ ..and..I am wondering.. what's the consequence/side effect to the wolfram system? Having inspected LD_LIBRARY_PATH in a new session shows: /opt/Wolfram/WolframEngine/10.3/SystemFiles/Libraries/Linux-ARM:/opt/\ Wolfram/WolframEngine/10.3/SystemFiles/Libraries/Linux-ARM/Mesa (I'm thinking best-practice etc etc) $\endgroup$
    – berrynice
    May 1 '16 at 6:47

Browse other questions tagged or ask your own question.