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:
SetEnvironment[
"PYTHONPATH" ->
"/usr/local/lib/python2.7/dist-packages:/usr/local/lib/python3.4/\
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:
#!/usr/bin/python
import pytumblr
consumer_key='xyz'
consumer_secret='xyz'
token_key = 'xyz'
token_secret='xyz'
client = pytumblr.TumblrRestClient(
consumer_key,
consumer_secret,
token_key,
token_secret
)
blogname = 'ABC'
client.create_text(blogname, state="published", slug="testing-post", title="Testing", body = "my text post..")
print('done')
I am stuck :-(.
SetEnvironment["LD_LIBRARY_PATH" -> ""]
first. $\endgroup$