【发布时间】:2022-03-25 04:41:39
【问题描述】:
Pyinstaller & shutil [function copy] 问题!
您好,我正在尝试将 .py 代码转换为 .exe 实际上我的代码与此类似:
dr = os.environ['WINDIR']
current = os.path.abspath(__file__)
shutil.copy(current, dr)
我们可以看到代码将当前的罚款复制到 windows 文件(这只是一个例子);该代码实际上工作正常,但如果我们将其编译为 exe 并运行它,我们会看到。
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'
错误来自函数副本,因为它在 \test\dist\test.py 中找不到 test.py 。
任何解决方案?
我试过了:
dr = os.environ['WINDIR']
current = os.path.abspath(__file__)
newfile = current.replace('py','exe')
shutil.copy(current, dr)
但它仍然说
IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\john
\\Desktop\\exeinstaller\\exeinstaller-2.0\\test\\dist\\test.exe'
【问题讨论】:
-
感谢搅拌机通过将 file 替换为 sys.argv[0]
标签: python python-2.7 pyinstaller ioerror shutil