windows7/python3.3/virtualenv/cx_Freeze/Import Error/MAXREPEAT
Let's use Python for serial communication! When it comes to, I think it's common (probably) to use Pyserial and Tkinter. However, in order for a program written in python to be usable by everyone, it is necessary to convert it into a form that does not depend on the Python environment. Therefore, we use a library called cx_Freeze to convert the python script into an exe file. I have summarized the errors that occurred at that time and their solutions.
First, in the process of converting .py files to .exe with cx_Freeze, an error occurs and the process stops. It seems that TCL_PARAMETER and TK_PARAMETER required to use tkinter cannot be imported.
Import Error
TCL_PARAMETER
You can add the path manually. In my case, it was a virtual environment using virtualenv, so I will add the following two lines to activate.bat.
set "TCL_LIBRARY=C:\Python33\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python33\tcl\tk8.5"
This will allow you to create an "temporary" exe file. However, it cannot be executed (◠‿◠)
If you are using a certain version of python, you will get the following error when launching the exe file.
Cannot import traceback module.
Exception:cannot import name MAXREPEAT
Original Exception:cannot import name MAXREPEAT
I didn't understand at all even if I went around, and I wrestled for more than 3 hours. I tried various things, but I will write the solution first.
If you are a python3 person, upgrade to python3.3.5. (I'm sorry for python2 people, but I don't know) MAXREPEAT cannot be imported because it is a bug in python3.3.0, so upgrading will fix it.
I'm sorry, I wrote it in English at first for various reasons, but it is troublesome to translate it into Japanese, so I will leave it in English ←
check sre_constants.py, sre_parse.py, sre_compile.py As the first refferece (bottom of this article) says, I tried to modify sre_constants.py, but the file of python33 was different from that of python27, so I couldn't try this solution. Next, I tried the solution mentioned in the second referrence, but it also didn't work.
install cx_Freeze in other ways
reference
Recommended Posts