[Pythonmac-SIG] Can I set an environment variable with py2app?
Ronald Oussoren
ronaldoussoren at mac.com
Tue Sep 1 20:47:15 CEST 2009
On 29 Aug, 2009, at 0:16, Christopher Barker wrote:
> Hi folks,
>
> I was using the Peppy editor, and it's spell checker relies on
> PyEnchant, which uses ctypes to use the enchant lib. I am using a
> macports enchant, so I had an environment variable set so that
> PyEnchant could find it:
>
> export PYENCHANT_LIBRARY_PATH=/opt/local/lib/libenchant.dylib
>
> This worked just great when I started Peppy from the command line,
> but when I started it from an application bundle, it failed, which
> I'm pretty sure is because apps started in bundles don't have the
> shell's environment variables.
That's right.
>
> I think there is a way to set a "global" environment variable in a
> plist somewhere, but I think it might be better to set it in the App
> bundle -- is there a way to do that?
The easiest way to do that is:
import os
os.environ["PYENCHANT_LIBRARY_PATH"] = "/opt/local/lib/libenchant.dylib"
If you do this before importing pyenchant it should pick up that
definition.
>
> For the moment, I've hacked the enchant module to look in the
> macports location, but I don't know if the maintainer will want to
> make that a permanent change. If he does, what would be the path to
> a fink enchant lib? we might as well add that too!
Hardcoding the library path would imho be a bad idea.
BTW. It would be much better to copy the library and its resources
into the application bundle, but that requires additional support in
py2app because it cannot automaticly detect the dependency to
libenchant.dylib.
Ronald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2224 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20090901/df734507/attachment.bin>
More information about the Pythonmac-SIG
mailing list