【问题标题】:error when compiling shitil with pyinstaller使用 pyinstaller 编译shitil 时出错
【发布时间】: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'

【问题讨论】:

标签: python python-2.7 pyinstaller ioerror shutil


【解决方案1】:

好像编译成exe文件时os.path.abspath(__file__)复制了编译前的文件位置,不作为变量处理。

【讨论】:

    猜你喜欢
    • 2012-02-19
    • 1970-01-01
    • 2020-09-13
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多