1

Pyinstaller & shutil [function copy] problem !

hi I'm trying to convert a .py code into .exe actually my code is similar to that :

 dr  = os.environ['WINDIR']
    current = os.path.abspath(__file__)
    shutil.copy(current, dr)

as we can see the code copy the current fine to windows file (this is just an example ) ; the code actually works fine but if we compile it into exe and run it we will see .

Traceback (most recent call last):
  File "<string>", line 13, in <module>
  File "C:\Documents and Settings\john\Desktop\pyinstaller\pyinstaller-2.0\test
\build\pyi.win32\test\out00-PYZ.pyz\shutil", line 119, in copy
  File "C:\Documents and Settings\john\Desktop\pyinstaller\pyinstaller-2.0\test
\build\pyi.win32\test\out00-PYZ.pyz\shutil", line 82, in copyfile
IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\john
\\Desktop\\pyinstaller\\pyinstaller-2.0\\test\\dist\\test.py'

the error is from function copy because it doesn't find test.py in \test\dist\test.py .

any solutions ?

i tried :

 dr  = os.environ['WINDIR']
    current = os.path.abspath(__file__)
    newfile = current.replace('py','exe')
    shutil.copy(current, dr)

but it still say

IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\john
\\Desktop\\exeinstaller\\exeinstaller-2.0\\test\\dist\\test.exe'
zey
  • 5,939
  • 14
  • 56
  • 110

1 Answers1

0

It seems that when compiling into exe file os.path.abspath(__file__) copies the file location before compiling and is not treated as a variable.