Interactive os.environ vs. os.environ in script
boris.smirnov at gmail.com
boris.smirnov at gmail.com
Mon Feb 26 10:49:44 EST 2007
On Feb 26, 4:32 pm, Peter Otten <__pete... at web.de> wrote:
> boris.smir... at gmail.com wrote:
> > Hi there,
>
> > I have a problem with setting environment variable in my script that
> > uses qt library. For this library I have to define a path to tell the
> > script whre to find it.
>
> > I have a script called "shrink_bs_070226" that looks like this:
> > **********************************
> > import sys, re, glob, shutil
> > import os
>
> > os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
>
> > from qt import *
> > ***********************
>
> > When I run this script I get this error:
>
> >> python shrink_bs_070226.py
> > Traceback (most recent call last):
> > File "shrink_bs_070226.py", line 25, in ?
> > from qt import *
> > File "/path/Linux/python/rh_linux/lib/python2.2/site-packages/
> > qt.py", line 46, in ?
> > import libsip
> > ImportError: libadamsqt.so: cannot open shared object file: No such
> > file or directory
>
> > What is important here that when I set this variable interactive in
> > python session, there is no problem with import.
>
> >> python
> > Python 2.2.3 (#1, Aug 8 2003, 08:44:02)
> > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-13)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> import os
>
> >>>> import shrink_bs_070226
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > File "shrink_bs_070226.py", line 25, in ?
> > from qt import *
> > ImportError: No module named qt
>
> >>>> os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
>
> >>>> import shrink_bs_070226
>
> > Could anybody explain me the logic here? Am I missing something?
>
> Until Python 2.4 a failed import could leave some debris which would make
> you think a second import did succeed.
>
> Try
>
> >>> import os
> >>> os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
> >>> import shrink_bs_070226 # I expect that to fail
>
> in a fresh interpreter to verify that what you see is an artifact of your
> test method.
>
> Peter- Hide quoted text -
>
> - Show quoted text -
You are right:
> python
Python 2.2.3 (#1, Aug 8 2003, 08:44:02)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
>>> import shrink_bs_070226
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "shrink_bs_070226.py", line 25, in ?
from qt import *
ImportError: No module named qt
>>>
OK then I have to reformulate my question. :)
In my script I have a line with
os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
but this line didn't work.
But when I set this environment variable in Linux shell it works. Here
is a small example.
> python shrink_bs_070226.py
Traceback (most recent call last):
File "shrink_bs_070226.py", line 25, in ?
from qt import *
File "/path/Linux/python/rh_linux/lib/python2.2/site-packages/
qt.py", line 46, in ?
import libsip
ImportError: libadamsqt.so: cannot open shared object file: No such
file or directory
> setenv LD_LIBRARY_PATH /path/Linux/rh_linux
> python shrink_bs_070226.py
Starting Script "Shrinker" ....
Why it's not working in script with command
os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
but in shell it works?
I hope it's understandable. :)
Thanks,
boris
More information about the Python-list
mailing list