windows7 / python3.3 / virtualenv / cx_Freeze / Import Error / MAXREPEAT

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.

Error that tends to occur when importing tkinter when converting to exe

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 (◠‿◠)

Case where the exed file cannot be started

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.

Solution

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.


What I tried

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 ←

  1. 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.

  2. install cx_Freeze in other ways

  1. change the version of Python the version of my Python3 was 3.3.0, so I changed it to 3.3.5, then it worked...

reference

  1. http://blog.goo.ne.jp/narisawanwan/e/4e936c8a519f3ec2eb1c10e25e8cb39d
  2. http://stackoverflow.com/questions/25316851/maxrepeat-importerror-when-using-cx-freeze-with-python-3-2

Recommended Posts

windows7 / python3.3 / virtualenv / cx_Freeze / Import Error / MAXREPEAT
Set-enable Python virtualenv on Windows
Install Python on Windows + pip + virtualenv
Import error even though python is installed
Virtualenv does not work on Python3.5 (Windows)
Import Error in Python3: No module named'xxxxx'
Python module import
Python on Windows
python windows environment
Python installation (Windows)
Import python script
python in virtualenv
Summarize Python import
[Note] Anaconda & VScode has trouble with python import error
I get an Import Error in Python Beautiful Soup
python windows environment construction
Python Not Implemented Error
Today's python error: killed
Python installation method Windows
Python from or import
python original module import
Python starting with Windows 7
Python error list (Japanese)
python basic on windows ②
Install python on windows
Import tsv with Python
[Python] What is virtualenv
Install Python (for Windows)
[Python] for statement error
Until you create Python Virtualenv on Windows and launch Jupyter
Import error resolution record when touching Python code from VSCode