Hi !
I have been finished my WMI information getter simple application, but the exe is not working as like the py modules before compilation.
The problem that when I started the program from CMD, the sys.argv is show the good path (in my machine the c:\dev\xxxx...) from Dialog1.py.
But when I compile it with Py2Exe, and try to start the exe, it has been not found the hwinfo.ini file what store the setup informations of the program.
This file is write by my hand, and I place it with Dialog1.exe (in same directory).
But the compiled exe is not use the good path... It use "/" only.
When I started it from CMD with Dialog1.exe, it hasn't been found the ini file:
Traceback (most recent call last):
File "Dialog1.py", line 269, in ?
File "Dialog1.py", line 201, in LoadIniFile
IOError: [Errno 2] No such file or directory: '/hwinfo.ini'
When I use full path: c:\dev\xxxx\Dialog1.exe, it have been found everything, and working good.
I don't understand it, because I working with sys.argv[0], with this method:
def LoadIniFile():
s=os.path.dirname(sys.argv[0])+'/hwinfo.ini'
f=open(s,'r')
l=(f.read()).split('\n')
d={}
for s in l:
if s.find('=')<>-1:
sl=s.split('=')
sl[0]=sl[0].strip().lower()
sl[1]=sl[1].strip()
d[sl[0]]=sl[1]
return d
So that folder is must be correct !
Why I get error ? What I can do if I want to use it as normal py ?
Thanx for help:
ft
Hi,
The problem that when I started the program from CMD, the sys.argv is
show the good path (in my machine the c:\dev\xxxx...) from Dialog1.py.
But when I compile it with Py2Exe, and try to start the exe, it has been
not found the hwinfo.ini file what store the setup informations of the
program.
But the compiled exe is not use the good path... It use "/" only.
As far as I understand (being new to py2exe, too) you get a single sys.path
only with a frozen (compiled into a exe) python app, pointing to your
library, and a sys.argv with only the name of your executable.
But if this file you want to open is inside the same dir your executable is
in, you can open it with just
myFile = file.open('hwinfo.ini', 'r')
Try C:\python23\Lib\site-packages\py2exe\examples\simple\hello.py
If you really need the path, test for frozen state
(e.g. hasattr(sys, 'frozen') ), and use sys.executable when frozen, your
usual sys.argv otherwise.
Regards,
Dave
···
Am Montag, 4. Juli 2005 16:48 schrieb fowlertrainer@anonym.hu:
"fowlertrainer@anonym.hu" <fowlertrainer@anonym.hu> writes:
Hi !
I have been finished my WMI information getter simple application, but
the exe is not working as like the py modules before compilation.
The problem that when I started the program from CMD, the sys.argv is
show the good path (in my machine the c:\dev\xxxx...) from Dialog1.py.
But when I compile it with Py2Exe, and try to start the exe, it has
been not found the hwinfo.ini file what store the setup informations
of the program.
This file is write by my hand, and I place it with Dialog1.exe (in
same directory).
But the compiled exe is not use the good path... It use "/" only.
When I started it from CMD with Dialog1.exe, it hasn't been found the
ini file:
Traceback (most recent call last):
File "Dialog1.py", line 269, in ?
File "Dialog1.py", line 201, in LoadIniFile
IOError: [Errno 2] No such file or directory: '/hwinfo.ini'
When I use full path: c:\dev\xxxx\Dialog1.exe, it have been found
everything, and working good.
I don't understand it, because I working with sys.argv[0], with this method:
def LoadIniFile():
s=os.path.dirname(sys.argv[0])+'/hwinfo.ini'
This isn't very robust. If I start a script (not with py2exe) like this
with 'myscript.py' then sys.argv[0] is an absolute pathname. If I start
it with 'python myscript.py' it is not an absolute but a relative
pathname. In the latter case your LoadIniFile() function uses the wrong
filename also. But if you use os.path.join() as you should, instead of
the +'/hwinfo,ini' it should work - both in the python script as in the
py2exe compiled case:
def LoadInitFile():
s = os.path.join(os.path.dirname(sys.argv[0]), 'hwinfo.ini')
...
Also, as the other poster suggested, in the compiled case sys.executable
contains an absolute path to your exe´.
Thomas