【发布时间】:2018-05-12 01:57:29
【问题描述】:
我创建了一个测试工具来检查是否有任何模块不能与 pyinstaller 一起使用,以便在我的主程序上使用 pyinstaller 之前解决它们。
当我尝试与我的脚本中的文件路径交互时,看起来 pyinstaller 创建的程序找不到我试图硬编码到脚本中的路径,例如“Z:\mkb\crew\mark_conrad\pictures\ psd_tool_test_files\test.psd”。我决定使用简单的 os.path.exists() 来调试这个谜,但没有运气。当我从 python 控制台运行我的调试程序时,它工作得很好,那么这里出了什么问题?
我是如何生成 exe 的: pyinstaller "Z:\mkb\programing\python\util\pyinstaller_library_tester.py"
Python 版本:2.7.15 PyInstaller 版本:3.3.1
领事输出:
Testing: Z:\mkb\crew\mark_conrad\pictures\psd_tool_test_files\test.psd
>>> This path does not exsist.
Path Results: False
Testing: Z:\\mkb\\crew\\mark_conrad\\pictures\\psd_tool_test_files\\test.psd
>>> This path does not exsist.
Path Results: False
Testing: Z:/mkb/crew/mark_conrad/pictures/psd_tool_test_files/test.psd
>>> This path does not exsist.
Path Results: False
Testing: Z://mkb//crew//mark_conrad//pictures//psd_tool_test_files//test.psd
>>> This path does not exsist.
Path Results: False
调试程序代码:
def checkingPaths(path,btn):
import os
if os.path.exists(path):
print '>>> Found a working path use this for your formats for paths'
print 'Path Results:',os.path.exists(path)
btn.configure(bg='#00cc30')
else:
print '>>> This path does not exsist.'
print 'Path Results:',os.path.exists(path)
btn.configure(bg='#ff0000')
def osTest(btn):
print r'Testing: Z:\mkb\crew\mark_conrad\pictures\psd_tool_test_files\test.psd'
checkingPaths("Z:\mkb\crew\mark_conrad\pictures\psd_tool_test_files\test.psd",btn)
print r'Testing: Z:\\mkb\\crew\\mark_conrad\\pictures\\psd_tool_test_files\\test.psd'
checkingPaths("Z:\\mkb\\crew\\mark_conrad\\pictures\\psd_tool_test_files\\test.psd",btn)
print r'Testing: Z:/mkb/crew/mark_conrad/pictures/psd_tool_test_files/test.psd'
checkingPaths("Z:/mkb/crew/mark_conrad/pictures/psd_tool_test_files/test.psd",btn)
print r'Testing: Z://mkb//crew//mark_conrad//pictures//psd_tool_test_files//test.psd'
checkingPaths("Z://mkb//crew//mark_conrad//pictures//psd_tool_test_files//test.psd",btn)
def tkinterTest():
import Tkinter as tk
root = tk.Tk()
osBtn = tk.Button(root,text='os Test',command =lambda: osTest(osBtn))
osBtn.pack(padx=10,pady=2,fill='x')
root.mainloop()
tkinterTest()
【问题讨论】:
标签: python python-2.7 pyinstaller