Orange Forum • View topic - Adding new modules to Mac OS Orange GUI

Adding new modules to Mac OS Orange GUI

A place to ask questions about methods in Orange and how they are used and other general support.

Adding new modules to Mac OS Orange GUI

Postby johnz » Mon Jun 24, 2013 21:29

I am using the Orange GUI (2.7rc1) under Mac OS Mountain Lion (10.8.4).
The Prototype -> SQL Widget needs to load the postgress python module and gives the error:
No module named psycopg2

which implies that the psycopg2 module is not on the sys.path

The Orange GUI has its own python environment in
/Applications/Orange.app/Contents/Frameworks/Python.framework/
which can be seen using the Data-> Python Script Plugin
Code: Select all
  import sys
  sys.path
  sys.argv[0]
  sys.executable

How can I install the psycopg2 module into the Orange python environment or add more libraries to the its internal sys.path

Re: Adding new modules to Mac OS Orange GUI

Postby johnz » Tue Jun 25, 2013 20:26

One method that worked for Mac OS 10.8 (Mountain Lion) is set the PYTHONPATH environment variable using the launchd.

This mechanism is very Mac OS version specific.
Is there a way to set the PYTHONPATH from within Orange?

Backgound:

The mechanism for setting environment variables passed to a Mac application launched from the Finder has changed from Mac OS 10.7 (Lion) to 10.8 (Mountain Lion). Mac 10.7 used the ~/.MacOSX/environment.plist, but this is no longer supported in Mac OS 10.8 .

The following steps follow the instructions from LaC in:
http://stackoverflow.com/questions/6037 ... n-mac-os-x

1) Put the following file in ~/Library/LaunchAgents/local.launchd.conf.plist:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>local.launchd.conf</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>launchctl < ~/.launchd.conf</string>   
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>


2) Set environment variables inside ~/.launchd.conf
Code: Select all
setenv PYTHONPATH <your_phython_install>/lib/python2.7/site-packages/

Note the value has to be an absolute string with no spaces and which does not expand other environment variables (i.e. $PYTHONPATH does not work)

3) Log out and log back in!
Launchd runs at login time and the daemon gives the environment to newly started processes.

4) Relaunch Orange and verify using the Python Script Widget
Code: Select all
import sys
sys.path
sys.argv[0]
sys.executable


5) To temporarily try this out, launchctl can be run anytime from the terminal and will effect any newly started processes, until launchd terminates at logout time.
Code: Select all
launchctl setenv PYTHONPATH <your_phython_install>/lib/python2.7/site-packages/
open /Applications/Orange.app

Re: Adding new modules to Mac OS Orange GUI

Postby Ales » Fri Jun 28, 2013 10:01

1. You can edit the '/Applications/Orange.app/Contents/MacOS/Orange' (or ENV in the same directory) to set your PYTHONPATH.

2. You could run
Code: Select all
/Applications/Orange.app/Contents/MacOS/pip install psycopg2

from the terminal (you will need Xcode to compile the extension). This will install the psycopg2 inside the application itself.

3. Install psycopg2 into your 'user' site-packages in $HOME/Library/Python/2.7/lib/python/site-packages/ (i.e. pip install --user).


Return to Questions & Support