AttributeError: After converting python script to EXE by Pyinstaller

China☆狼群 提交于 2019-12-12 02:17:24

问题


I have made a python script for calculations purposes, importing libraries, Tkinter, Pmw, sympy, math, tkfiledialog, webbrowser.

Now, by using Pyinstaller I convert it into an EXE application. When I run it, it gives the error:

WindowsError: [Error 3] The system cannot find the path specified: 'C:\\Python27\\Earthing\\dist\\Earthing\\Pmw/*.*'

So, I copy and paste the entire Pmw directory on this location. However, after doing this, I get the error:

AttributeError: 'module' object has no attribute 'OptionMenu'

Now, how do I resolve this error? Please do help me sort this out.


回答1:


I ran into the same problem. It is due to what I would call 'dynamic imports', made mostly in PmwLoader.py (placed in lib subfolder): PmwLoader loads all the files, and the they become attributes of Pmw global library.

The solution I found was to manually delete the line 'import Pmw' in all the wanted Pmw files (I only used PmwComboBox and PmwScrolledFrame). PmwCombobox and PmwScrolledFrame notably need to import other Pmw files, so I had to replace import Pmw by

import PmwBase
import PmwScrolledListBox
import PmwEntryField
import PmwTimeFuncs

and then do the same in PmwScrolledListBox and PmwEntryFiled.

The the fun is to solve the bugs --notably replace a lot of the MegaWidget by PmwBase.MegaWidget, and so on.

In the end, it does not take more than one hour.

Good luck! t.



来源:https://stackoverflow.com/questions/30886562/attributeerror-after-converting-python-script-to-exe-by-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!