问题
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