4

I encountered and solved this problem earlier this day and now I run into something similar but in another context.

When I fire up python (2.7) in my mac Terminal (Mac OS Lion) and do

import oursql

everything is fine.

When I do the same within a python script in the Aptana IDE I get the following error.

    Traceback (most recent call last):
  File "/Users/salah/Documents/Aptana Studio 3 Workspace/pubmap/src/scripts/parse_all_dblp_authors.py", line 10, in <module>
    import oursql
ImportError: dlopen(/Library/Python/2.7/site-packages/oursql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/oursql.so
  Reason: image not found

This is the same error as in the problem above which I used to solve by adding

PATH=${PATH}:/usr/local/mysql/bin
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"

to .bashrc and

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

to .bash_profile.

Why does this have no effect on Aptana? By the way Aptana is a derivate of eclipse so everything relevant to eclipse should be relevant to Aptana, too - at least I think so...

Edit:

A suggestion by Peter in his answer below brought me a possible solution. Just set the path right into the interpreter Options of Python in Aptana/Eclipse/Pydev. See the following Screenshot:

Interpreter Settings for Aptana

Community
  • 1
  • 1
Aufwind
  • 25,310
  • 38
  • 109
  • 154
  • Perhaps aptana/Eclipse simply sets the python path differently? – matt b Jul 21 '11 at 20:46
  • @matt b: Is there a way to determine that? – Aufwind Jul 21 '11 at 21:57
  • 1
    I find the best way to debug python search path problems is to examine them at runtime. `os.environ['PATH']` will show you the PATH environment variable python has been given. [`sys.path`](http://docs.python.org/library/sys.html#sys.path) is the path python is using to search for modules. – Peter Graham Jul 22 '11 at 00:30

2 Answers2

3

It's been a while since I used Pydev, but the Pydev docs on configuring the interpreter are probably worth a look.

Python IDEs usually let you configure the environment python is run in when you run from the IDE.

Also, having .bashrc change your $PATH will only change the environment variable for bash sessions. Unless you run Aptana from bash changing your .bashrc won't change the envirnment variables Aptana gets. See setting-environment-variables-in-os-x.

Community
  • 1
  • 1
Peter Graham
  • 11,323
  • 7
  • 40
  • 42
  • Your first link brought me enlightenment. I just went to the Interpreter options of python and added "/usr/local/mysql/lib/" as environment variable to the **Environment** section. I posted a screenshot as Edit to my question. Thank you! – Aufwind Jul 22 '11 at 12:19
1

Aptana Studio does not read .bashrc. However it does include other files in the following order:

if [ -f /etc/profile ] ; then . /etc/profile; fi   

if [ -f ~/.bash_profile ] ; then . ~/.bash_profile;
elif [ -f ~/.bash_login ] ; then . ~/.bash_login;
elif [ -f ~/.profile ] ; then . ~/.profile;

[[ -f ~/.aptanarc ]] && . ~/.aptanarc

Cheers, Max

Max
  • 2,917
  • 1
  • 16
  • 16
  • 1
    I mentioned above, how I source .bashrc in bash_profile. If Aptana includes .bash_profile, wouldn't .bashrc be loaded automatically? – Aufwind Jul 22 '11 at 12:12