Short answer: The directory is there (I was mistaken about it being
missing), but the file my script uses is not.

Long answer: I wonder if I've somehow got something weird in my
environments.  As mentioned in my other topic, I was able to run the
Build.py script with my real project and with a test script called
copyfile.py if I had the files on the C: drive in the Windows XP VM
(VirtualBox) on my Ubuntu 9.04 laptop at home; if the files were on a
network mapped drive, I got "No such file or directory: 'DATA'" errors, and
I am getting those same errors on the XP VM on Ubuntu 9.10 on my machine at
the office.  Today, I brought my laptop from home into the office, and now
I'm getting the same "No such file or directory: 'DATA'" error, where it had
been working fine just last night.  So, here's my simple script, called
copyfile.py:

#!/usr/bin/python
# Copy a file.  The file is included in the --onefile output of pyinstaller.
import os
import shutil
# prompts for input are so I can see what is happening
ans = raw_input("Enter a letter: ")
src = os.path.join(os.environ['_MEIPASS2'], 'zeus.p12')
dest = "./Bzeus.p12"
shutil.copy(src,dest)
ans = raw_input("Enter a number: ")

The script sits in c:\fdu, so then, while I'm in the c:\fdu directory I run
c:\python25\python.exe c:\pyinstaller\Makespec.py -X --onefile copyfile.py

and it responds
wrote C:\fdu\copyfile.spec
now run Build.py to build the executable

Then I edit the spec file, adding the a.datas line, so that it looks like
this:
# -*- mode: python -*-
a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'),
os.path.join(HOMEPATH,'support\\useUnicode.py'), 'copyfile.py'],
             pathex=['C:\\fdu'])
a.datas += [('C:\\fdu\\zeus.p12','DATA','zeus.p12')]
pyz = PYZ(a.pure)
exe = EXE( pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'copyfile.exe'),
          debug=False,
          strip=False,
          upx=True,
          console=True )

Then I run
c:\python25\python.exe c:\pyinstaller\Build.py copyfile.spec

At home on my laptop it worked,  (I don't have the output handy) producing
copyfile.exe, but which then gave an error about not being able to find the
zeus.p12 file.  But now on that same laptop but in the office, as well as on
my office machine, it gives me this:

checking Analysis
building because copyfile.py changed
running Analysis outAnalysis0.toc
Analyzing: c:\pyinstaller\support\_mountzlib.py
Analyzing: c:\pyinstaller\support\useUnicode.py
Analyzing: copyfile.py
W: Cannot determine your Windows or System directories
W: Please add them to your PATH if .dlls are not found
W: or install http://sourceforge.net/projects/pywin32/
C:\fdu\build\pyi.win32\copyfile\outAnalysis0.toc no change!
checking PYZ
checking PKG
building because copyfile.py changed
building PKG outPKG3.pkg
Cannot find ('C:\fdu\zeus.p12', 'DATA', 0, 'b')
Traceback (most recent call last):
  File "c:\pyinstaller\Build.py", line 1160, in <module>
    main(args[0], configfilename=opts.configfile)
  File "c:\pyinstaller\Build.py", line 1148, in main
    build(specfile)
  File "c:\pyinstaller\Build.py", line 1111, in build
    execfile(spec)
  File "copyfile.spec", line 15, in <module>
    console=True )
  File "c:\pyinstaller\Build.py", line 661, in __init__
    strip_binaries=self.strip, upx_binaries=self.upx, crypt=self.crypt)
  File "c:\pyinstaller\Build.py", line 561, in __init__
    self.__postinit__()
  File "c:\pyinstaller\Build.py", line 196, in __postinit__
    self.assemble()
  File "c:\pyinstaller\Build.py", line 618, in assemble
    archive.build(self.name, mytoc)
  File "c:\pyinstaller\archive.py", line 229, in build
    self.add(tocentry)   # the guts of the archive
  File "c:\pyinstaller\carchive.py", line 235, in add
    s = open(pathnm, 'rb').read()
IOError: [Errno 2] No such file or directory: 'DATA'

I must be doing something incorrectly, but I can't see what it is.  Perhaps
it's related to the warning about it not being able to determine the Windows
or System directories (?).

Peter


On Wed, Mar 31, 2010 at 4:34 AM, Giovanni Bajo <[email protected]> wrote:

> On Tue, 2010-03-30 at 20:08 -0600, Peter Scheie wrote:
> > In my python script, I'm trying to copy a file from
> > os.environ['_MEIPASS2'], which appears to point to
> > C:/DOCUME~1/PETER/LOCALS~1/Temp/_MEI5322/. The file is supposed to be
> > placed there by the a.datas method in the spec file. However, the
> > directory doesn't exist.  Is this something I have to create in my
> > script so that the script can place the file (included in the .exe)
> > there at run time?  I was under the impression that it was created
> > automatically/dynamically.
>
> The directory is created at startup and removed after the application
> exits. I am not aware of any bug where _MEIPASS2 at runtime points to a
> directory which it does not exist, and it sounds very weird to me.
>
> Can you reproduce your problem with a working program that you can
> share?
>
>
> --
> Giovanni Bajo   ::  [email protected]
> Develer S.r.l.  ::  http://www.develer.com
>
> My Blog: http://giovanni.bajo.it
> Last post: C++ and copy-on-write data structures
>
> --
> You received this message because you are subscribed to the Google Groups
> "PyInstaller" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<pyinstaller%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pyinstaller?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyinstaller?hl=en.

Reply via email to