473,729 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interactive os.environ vs. os.environ in script

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_0702 26" that looks like this:
*************** *************** ****
import sys, re, glob, shutil
import os

os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'

from qt import *
*************** ********

When I run this script I get this error:

python shrink_bs_07022 6.py
Traceback (most recent call last):
File "shrink_bs_0702 26.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_07022 6
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "shrink_bs_0702 26.py", line 25, in ?
from qt import *
ImportError: No module named qt
>>os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'
>>import shrink_bs_07022 6
Could anybody explain me the logic here? Am I missing something?
Thank in advance.
Rg
Boris

Feb 26 '07 #1
9 3746
bo***********@g mail.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_0702 26" that looks like this:
*************** *************** ****
import sys, re, glob, shutil
import os

os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'

from qt import *
*************** ********

When I run this script I get this error:

>python shrink_bs_07022 6.py
Traceback (most recent call last):
File "shrink_bs_0702 26.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_07022 6
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "shrink_bs_0702 26.py", line 25, in ?
from qt import *
ImportError: No module named qt
>>>os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'
>>>import shrink_bs_07022 6

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_PAT H"]='/path/Linux/rh_linux'
import shrink_bs_07022 6 # I expect that to fail
in a fresh interpreter to verify that what you see is an artifact of your
test method.

Peter
Feb 26 '07 #2
On Feb 26, 4:32 pm, Peter Otten <__pete...@web. dewrote:
boris.smir...@g mail.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_0702 26" that looks like this:
*************** *************** ****
import sys, re, glob, shutil
import os
os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'
from qt import *
*************** ********
When I run this script I get this error:
python shrink_bs_07022 6.py
Traceback (most recent call last):
File "shrink_bs_0702 26.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_07022 6
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "shrink_bs_0702 26.py", line 25, in ?
from qt import *
ImportError: No module named qt
>>os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'
>>import shrink_bs_07022 6
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_PAT H"]='/path/Linux/rh_linux'
import shrink_bs_07022 6 # 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_PAT H"]='/path/Linux/rh_linux'
>>import shrink_bs_07022 6
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "shrink_bs_0702 26.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_PAT H"]='/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_07022 6.py
Traceback (most recent call last):
File "shrink_bs_0702 26.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_07022 6.py
Starting Script "Shrinker" ....

Why it's not working in script with command

os.environ["LD_LIBRARY_PAT H"]='/path/Linux/rh_linux'

but in shell it works?

I hope it's understandable. :)
Thanks,
boris

Feb 26 '07 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

bo***********@g mail.com wrote:
>
OK then I have to reformulate my question. :)

In my script I have a line with

os.environ["LD_LIBRARY_PAT H"]='/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_07022 6.py
Traceback (most recent call last): File "shrink_bs_0702 26.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
ld-elf.so reads environment variables when it was loaded.
It never reads environment variables again!
That you setting environment in the process does not make link-editor
to re-read environment variable and take effect.

To resolve the problem, you can try to add the path to sys.path.

- --
Thinker Li - th*****@branda. to th********@gmai l.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4w6H1LD UVnWfY8gRAoI0AK CLikYsFU2N6aaOZ FDd1L2KY8DjqACg 3QQn
KsEEcrvpw1CktEk VCKe/ojk=
=EQG6
-----END PGP SIGNATURE-----

Feb 26 '07 #4
On Feb 26, 5:44 pm, Thinker <thin...@branda .towrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

boris.smir...@g mail.com wrote:
OK then I have to reformulate my question. :)
In my script I have a line with
os.environ["LD_LIBRARY_PAT H"]='/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_07022 6.py
Traceback (most recent call last): File "shrink_bs_0702 26.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

ld-elf.so reads environment variables when it was loaded.
It never reads environment variables again!
That you setting environment in the process does not make link-editor
to re-read environment variable and take effect.

To resolve the problem, you can try to add the path to sys.path.

- --
Thinker Li - thin...@branda. to thinker...@gmai l.comhttp://heaven.branda.t o/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla -http://enigmail.mozdev .org

iD8DBQFF4w6H1LD UVnWfY8gRAoI0AK CLikYsFU2N6aaOZ FDd1L2KY8DjqACg 3QQn
KsEEcrvpw1CktEk VCKe/ojk=
=EQG6
-----END PGP SIGNATURE------ Hide quoted text -

- Show quoted text -
Hi,
thanks for the tip, but it didn't help.

I used:
sys.path.append ('/path/Linux/rh_linux')

and the problem still persists:

Traceback (most recent call last):
File "shrink_bs_0702 26.py", line 26, 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

Is there another possibility of how to solve it just by adding some
lines in script?

Thanks
Boris

Feb 27 '07 #5
bo***********@g mail.com wrote:
Is there another possibility of how to solve it just by adding some
lines in script?
I think you have to wrap your script in a shell script

#!/bin/sh
export LD_LIBRARY_PATH =/path/Linux/rh_linux
python shrink_bs_07022 6.py

To avoid that you can have the python script invoke itself, e. g.:

#!/usr/bin/env python
import os
if os.environ.get( "YADDA") != "whatever":
print "fix environment"
os.environ["YADDA"] = "whatever"
os.system("yadd a.py")
raise SystemExit

print "YADDA is now %r" % os.environ["YADDA"]
print "do your real stuff"

Peter

Feb 27 '07 #6
On Feb 27, 9:31 am, Peter Otten <__pete...@web. dewrote:
boris.smir...@g mail.com wrote:
Is there another possibility of how to solve it just by adding some
lines in script?

I think you have to wrap your script in a shell script

#!/bin/sh
export LD_LIBRARY_PATH =/path/Linux/rh_linux
python shrink_bs_07022 6.py

To avoid that you can have the python script invoke itself, e. g.:

#!/usr/bin/env python
import os
if os.environ.get( "YADDA") != "whatever":
print "fix environment"
os.environ["YADDA"] = "whatever"
os.system("yadd a.py")
raise SystemExit

print "YADDA is now %r" % os.environ["YADDA"]
print "do your real stuff"

Peter
Thanks for the reply.

If I that good understood I did this:
*************** *************** ****
import sys, re, glob, shutil
import os
if os.environ["LD_LIBRARY_PAT H"].count('/path/Linux/rh_linux') !=1:
os.environ["LD_LIBRARY_PAT H"]=os.environ["LD_LIBRARY_PAT H"]+':'+'/
path/Linux/rh_linux'
os.system("shri nk_bs_070226.py ")
raise SystemExit

from qt import *
*************** ********

Is that correct. If yes then it not works. If not then, what's wrong?
python shrink_bs_07022 6.py
Traceback (most recent call last):
File "./shrink_bs_07022 6.py", line 29, in ?
from qt import *
ImportError: No module named qt

Thanks
Boris

Feb 27 '07 #7
bo***********@g mail.com wrote:
On Feb 27, 9:31 am, Peter Otten <__pete...@web. dewrote:
>boris.smir...@ gmail.com wrote:
Is there another possibility of how to solve it just by adding some
lines in script?

I think you have to wrap your script in a shell script

#!/bin/sh
export LD_LIBRARY_PATH =/path/Linux/rh_linux
python shrink_bs_07022 6.py

To avoid that you can have the python script invoke itself, e. g.:

#!/usr/bin/env python
import os
if os.environ.get( "YADDA") != "whatever":
print "fix environment"
os.environ["YADDA"] = "whatever"
os.system("yadd a.py")
raise SystemExit

print "YADDA is now %r" % os.environ["YADDA"]
print "do your real stuff"

Peter

Thanks for the reply.

If I that good understood I did this:
*************** *************** ****
import sys, re, glob, shutil
import os
if os.environ["LD_LIBRARY_PAT H"].count('/path/Linux/rh_linux') !=1:
os.environ["LD_LIBRARY_PAT H"]=os.environ["LD_LIBRARY_PAT H"]+':'+'/
path/Linux/rh_linux'
os.system("shri nk_bs_070226.py ")
raise SystemExit

from qt import *
*************** ********

Is that correct. If yes then it not works. If not then, what's wrong?
I don't know. You are not quoting the actual code you are using (from qt
import * is definitely not in line 29, and the #!/path/to/your/python is
missing). Do you have more than one python version installed? then you may
have to put

#!/usr/bin/python2.2

or similar in the first line of your script.

Peter
Feb 27 '07 #8
On Feb 27, 10:33 am, Peter Otten <__pete...@web. dewrote:
boris.smir...@g mail.com wrote:
On Feb 27, 9:31 am, Peter Otten <__pete...@web. dewrote:
boris.smir...@g mail.com wrote:
Is there another possibility of how to solve it just by adding some
lines in script?
I think you have to wrap your script in a shell script
#!/bin/sh
export LD_LIBRARY_PATH =/path/Linux/rh_linux
python shrink_bs_07022 6.py
To avoid that you can have the python script invoke itself, e. g.:
#!/usr/bin/env python
import os
if os.environ.get( "YADDA") != "whatever":
print "fix environment"
os.environ["YADDA"] = "whatever"
os.system("yadd a.py")
raise SystemExit
print "YADDA is now %r" % os.environ["YADDA"]
print "do your real stuff"
Peter
Thanks for the reply.
If I that good understood I did this:
*************** *************** ****
import sys, re, glob, shutil
import os
if os.environ["LD_LIBRARY_PAT H"].count('/path/Linux/rh_linux') !=1:
os.environ["LD_LIBRARY_PAT H"]=os.environ["LD_LIBRARY_PAT H"]+':'+'/
path/Linux/rh_linux'
os.system("shri nk_bs_070226.py ")
raise SystemExit
from qt import *
*************** ********
Is that correct. If yes then it not works. If not then, what's wrong?

I don't know. You are not quoting the actual code you are using (from qt
import * is definitely not in line 29, and the #!/path/to/your/python is
missing). Do you have more than one python version installed? then you may
have to put

#!/usr/bin/python2.2

or similar in the first line of your script.

Peter- Hide quoted text -

- Show quoted text -
Probably I understood it not correctly. What did you mean was to put
that code into my python script "shrink_bs_0702 26.py" and then calls
script itself?

So I took my script "shrink_bs_0702 26.py" and it starts with:
*************** *************** ****
#!/usr/bin/env python
import sys, re, glob, shutil
import os

then I put your code in that script

if os.environ["LD_LIBRARY_PAT H"].count('/path/Linux/rh_linux') !=1:
os.environ["LD_LIBRARY_PAT H"]=os.environ["LD_LIBRARY_PAT H"]+':'+'/
path/Linux/rh_linux'
os.system("shri nk_bs_070226.py ")
raise SystemExit

and here continues my script:

from qt import *

......
*************** ********

Is it correct?

BTW: On lines 3:18 I have comments, script description and
modifications, therefore is "from qt import *" on the line 29

Feb 27 '07 #9
bo***********@g mail.com wrote:
Probably I understood it not correctly. What did you mean was to put
that code into my python script "shrink_bs_0702 26.py" and then calls
script itself?
Yes.
So I took my script "shrink_bs_0702 26.py" and it starts with:
*************** *************** ****
#!/usr/bin/env python
import sys, re, glob, shutil
import os

then I put your code in that script

if os.environ["LD_LIBRARY_PAT H"].count('/path/Linux/rh_linux') !=1:
os.environ["LD_LIBRARY_PAT H"]=os.environ["LD_LIBRARY_PAT H"]+':'+'/
path/Linux/rh_linux'
os.system("shri nk_bs_070226.py ")
raise SystemExit

and here continues my script:

from qt import *

.....
*************** ********

Is it correct?
Yes.
BTW: On lines 3:18 I have comments, script description and
modifications, therefore is "from qt import *" on the line 29
The problem must be something else, then.

Peter

Feb 27 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10184
by: Yun Mao | last post by:
Hi, How to make changes to os.environ and os.path.chdir still effective after I run the script? Currently, the changes are only good within my script. I would like the shell who called python myprog.py also gets the change.. Thank you! Yun
1
3834
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System Properties"->Advanced->"Environment Variables". However, if I open a console and type 'set', "SSID" is not listed; also if I open a python shell and do os.environ the variable is not found. What am I doing wrong??? import _winreg
0
1185
by: Iván Cabria | last post by:
Hi, thanks to Jeff Epler for the answer. I have tried his suggestion and I have added two lines after the first line in the python script: import os os.environ = "/bin/bash"
0
1206
by: Iván Cabria | last post by:
Hi again, I have checked that the shell is the bash shell by running again the script with a print statement. The first four lines are: #!/usr/local/bin/python import os os.environ = "/bin/bash" print os.environ I have also read in Internet, in the following message about a
0
1317
by: mahongquan | last post by:
when i install moinmoin in python 2.4,windows server2000, I found it has a bug,cgiHttpServer.py set environ,but the cgi python script can not get the environ variant,such as environ,so moin donot display correct web page.
20
2446
by: Joe | last post by:
When you run "python -i scriptname.py" after the script completes you left at the interactive command prompt. Is there a way to have this occur from a running program? In other words can I just run scriptname.py (NOT python -i scriptname.py) and inside of scriptname.py I decide that I want to fall back to the interactive prompt? I've searched and so far the only thing I've come up with is to use pdb, but
11
3938
by: jim.eggleston | last post by:
Windows doesn't have a HOME environment variable, but it does have HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically populate os.environ with HOME, where HOME = os.path.join(os.environ, os.environ)? If this was done, then modules such as pdb, which load resource files from HOME, would work under Windows. Alternatively, here is a patch to make pdb.py read .pdbrc under Windows.
2
2903
by: eight02645999 | last post by:
hi i am writing a CGI to process some database transactions using the Sybase module. so in my CGI script, i have: .... import Sybase import cgitb; cgitb.enable(display=1 , logdir="/tmp/weblog.txt") .... ....
4
2640
by: j_macaroni | last post by:
I know you can start php -a and go into interactive mode. This works well exept you have to keep putting <?php code here ; bla blah code ; Couple of problems with this. 1) Exits php when you make an error. 2) When you type a command; it displays the result but does not do an automatic CR/LF
0
8764
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9289
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9210
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9156
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3242
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.