LoginSignup
2
2

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-08-28

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

Pythonを使ってシリアル通信をしよう!となったとき、PyserialとTkinterを使うっていうのはよくある(たぶん)と思います。ただ、pythonで書かれたプログラムをみんなが使えるようにするためにはPythonの環境に依存しない形に変換する必要がありますよね。そこで、cx_Freezeというライブラリを使ってpythonスクリプトをexeファイルに変換します。その時に起こったエラーとその解決方法についてまとめました。

exe化する際にtkinterをimportする場合に発生しがちなエラー

まず、cx_Freezeで.pyのファイルを.exeに変換する過程でエラーが発生して処理がストップします。
tkinterを使用するのに必要なTCL_PARAMETERとTK_PARAMETERがインポートできないっぽいです。

Import Error
TCL_PARAMETER

手動でパスを追加してやれば良いです。僕の場合、virtualenvを使った仮想環境だったので、activate.batに以下の二行を追加してやります。

set "TCL_LIBRARY=C:\Python33\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python33\tcl\tk8.5"

こうすると、”とりあえず”exeファイルを作ることができるようになります。ただ、実行はできません( ◠‿◠ )

exe化したファイルを起動できないケース

もしあなたがある特定のバージョンのpythonを利用していた場合、exeファイルを起動すると以下のエラーが出ます。

Cannot import traceback module.
Exception:cannot import name MAXREPEAT
Original Exception:cannot import name MAXREPEAT

ぐぐってもさっぱりわからず、3時間以上格闘しました。
いろいろ試しましたが、解決方法を先に書いておきます。

解決方法

python3の人はpython3.3.5にアップグレードしましょう。(python2の人はすいませんがわかりません)
MAXREPEATがimportできないのはpython3.3.0のバグなので、アップグレードすれば直ります。


僕がトライした内容

すいません、最初は諸事情で英語で書いたのですが日本語に訳すのが面倒なので英語のままにしておきます←

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

3. 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
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2