質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

3回答

1356閲覧

Pythonのexeファイル化ができません

Rena_StarPrince

総合スコア1

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/11/02 13:20

下記のコードでブロック崩しのゲームをexeファイル化しようとしましたができません。

pip install pyinstaller
pyinstaller ブロック崩し.py --onefile
というコマンドを打ち込みexeファイル化はできるのですが、コマンドプロンプトが開いた後すぐ閉じてしまいます。
どうすればよいでしょうか。

Ptthonは3.6を利用しています。

Python

1コード 2#!python.3.6 3#ブロック崩し 4 5import tkinter as tk 6from tkinter import messagebox 7 8#変数(追加) 9score=0 10time=0 11index=0 12 13#キー 14key="" 15def key(e): 16 global key 17 key=e.keysym 18 19#ウィンドウ 20win=tk.Tk() 21win.title("ブロック崩し") 22win.geometry("425x625") 23win.resizable 24win.bind("<KeyPress>", key) 25 26#キャンバス 27can=tk.Canvas(bg="black",width=400,height=600) 28can.place(x=10,y=10) 29 30 31#ゲームオーバー 32def gameOver(): 33 if index==1 or index==2 or index==3: 34 messagebox.showinfo("Information","GAME OVER") 35 exit() 36 37#ゲームクリア 38def gameClear(): 39 if index==1 or index==2 or index==3: 40 messagebox.showinfo("Information","CONGRATURATIONS") 41 exit() 42 43#ボール 44global bx 45global by 46ball_x=50 47ball_y=500 48bx=5 49by=-5 50 51def drawBall(): 52 global ball_x 53 global ball_y 54 global bx 55 global by 56 ball_id = can.create_oval(0, 0, 20, 20, fill="white") 57 can.coords(ball_id, ball_x, ball_y, ball_x+20, ball_y+20) 58 if ball_x<=0 or ball_x>=385: 59 bx *=-1 60 if ball_y<=0: 61 by *= -1 62 if ball_y>=600: 63 gameOver() 64 if ball_y>=560 and ball_x>=rack_x-10 and ball_x<=rack_x+70: 65 by *=-1 66 67 ball_x += bx;ball_y += by 68 69#ボールスピード 70 71 72 73#ラケット 74rack_x=170 75keyPress_R=False 76keyPress_L=False 77def rightKeyPress(event): 78 global keyPress_R 79 keyPress_R=True 80def rightKeyRelease(event): 81 global keyPress_R 82 keyPress_R=False 83def leftKeyPress(event): 84 global keyPress_L 85 keyPress_L=True 86def leftKeyRelease(event): 87 global keyPress_L 88 keyPress_L=False 89win.bind("<KeyPress-Right>",rightKeyPress) 90win.bind("<KeyRelease-Right>",rightKeyRelease) 91win.bind("<KeyPress-Left>",leftKeyPress) 92win.bind("<KeyRelease-Left>",leftKeyRelease) 93 94 95def drawRacket(): 96 global rack_x 97 can.create_rectangle(rack_x,580,rack_x+60,595,fill="white") 98 if keyPress_R==True and rack_x<=350: 99 rack_x +=5 100 if keyPress_L==True and rack_x>=-10: 101 rack_x-=5 102 103#ブロック1 104block=[] 105for x in range(5): 106 for y in range(4): 107 block.append({"x":x*80+5,"y":y*40+10,"st":1}) 108def drawBlock(): 109 global ball_x 110 global ball_y 111 global by 112 global score#(追加) 113 block_count=0 114 for i in range(len(block)): 115 x=block[i]["x"] 116 y=block[i]["y"] 117 st=block[i]["st"] 118 if ball_y<=y+30 and ball_x>=x-10 and ball_x<=x+60 and st==1: 119 by*=-1 120 block[i]["st"]=0 121 score=score+10#(追加) 122 if st==1: 123 can.create_rectangle(x,y,x+70,y+30,fill="white") 124 block_count+=1 125 if block_count==0: 126 gameClear() 127 128#スコア(追加) 129def drawScore(): 130 can.create_text(30,550,text="SCORE:"+str(score),fill="white") 131 132#時間 133def drawTime(): 134 can.create_text(30,570,text="Time:"+str(time),fill="white") 135 136#画面推移(追加) 137def gamemain(): 138 global index 139 if index==0: 140 can.create_text(200,100,text="ブロック崩し",anchor="center",font=("HG丸ゴシックM-PRO",24),fill="white") 141 can.create_text(200,500,text="Press [1]Easy",anchor="center",font=("HG丸ゴシックM-PRO",24),fill="white") 142 can.create_text(200,535,text="[2]Normal",anchor="center",font=("HG丸ゴシックM-PRO",24),fill="white") 143 can.create_text(200,570,text="[3]Hard",anchor="center",font=("HG丸ゴシックM-PRO",24),fill="white") 144 if key=="1": 145 index=1 146 elif key=="2": 147 index=2 148 elif key=="3": 149 index=3 150 can.after(15,gamemain) 151 152 elif index==1: 153 global bx 154 global by 155 bx=5 156 by=-5 157 def gameLoop(): 158 can.delete("all") 159 drawBall() 160 drawRacket() 161 drawBlock() 162 drawScore()#(追加) 163 drawTime()#追加 164 win.after(50,gameLoop) 165 gameLoop() 166 167 elif index==2: 168 bx=7 169 by=-7 170 def gameLoop(): 171 can.delete("all") 172 drawBall() 173 drawRacket() 174 drawBlock() 175 drawScore()#(追加) 176 drawTime()#追加 177 win.after(50,gameLoop) 178 gameLoop() 179 180 elif index==3: 181 bx=10 182 by=-10 183 def gameLoop(): 184 can.delete("all") 185 drawBall() 186 drawRacket() 187 drawBlock() 188 drawScore()#(追加) 189 drawTime()#追加 190 win.after(50,gameLoop) 191 gameLoop() 192 193#表示ループ 194gamemain() 195 196 197#ウィンドウループ 198win.mainloop 199 200

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答3

0

ベストアンサー

1箇所変えただけで動きましたよ。

#ウィンドウループ win.mainloop() <ー括弧をつける

C:¥> pyinstaller BlockTennis.py --onefile --noconsole

イメージ説明

投稿2021/11/03 02:26

technocore

総合スコア7225

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ソースコード末尾の

python

1win.mainloop

python

1win.mainloop()

の間違いでしょう。ウィンドウが表示されない原因はこれだと思います。
同様に

python

1win.resizable

python

1win.resizable(0, 0)

の間違いでしょう。

投稿2021/11/02 23:41

etherbeg

総合スコア1195

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

起動したはいいけど、エラーが出てすぐ終了するんでしょう。
Windows上から起動せずに、あらかじめコマンドプロンプトを開いておいて、そこから起動させてみれば、エラーメッセージが見れるかもしれません

投稿2021/11/02 13:25

y_waiwai

総合スコア87774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Rena_StarPrince

2021/11/02 13:43

コメントありがとうございます。 --debugを付け足したら出たメッセージを下記に記します。
Rena_StarPrince

2021/11/02 13:45

# collections not found in PYZ # operator not found in PYZ import '_operator' # <class '_frozen_importlib.BuiltinImporter'> import operator # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\operator.pyc # keyword not found in PYZ import keyword # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\keyword.pyc # heapq not found in PYZ import '_heapq' # <class '_frozen_importlib.BuiltinImporter'> import heapq # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\heapq.pyc import 'itertools' # <class '_frozen_importlib.BuiltinImporter'> # reprlib not found in PYZ import reprlib # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\reprlib.pyc import '_collections' # <class '_frozen_importlib.BuiltinImporter'> import collections # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\collections\__init__.pyc # functools not found in PYZ import '_functools' # <class '_frozen_importlib.BuiltinImporter'> # types not found in PYZ # collections.abc not found in PYZ import collections.abc # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\collections\abc.pyc import types # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\types.pyc # weakref not found in PYZ import weakref # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\weakref.pyc import functools # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\functools.pyc # importlib not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\importlib\__init__.pyc' # warnings not found in PYZ import warnings # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\warnings.pyc import 'importlib' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01B48F70> # importlib.util not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\importlib\util.pyc' # importlib.abc not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\importlib\abc.pyc' # importlib.machinery not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\importlib\machinery.pyc' import 'importlib.machinery' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01B71F70> import 'importlib.abc' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01B71AF0> # contextlib not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\contextlib.pyc' import 'contextlib' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01B85690> import 'importlib.util' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01B71510> import 'pkgutil' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01A51850> [26652] LOADER: Running pyi_rth_inspect.py # inspect not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\inspect.pyc' # ast not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\ast.pyc' import '_ast' # <class '_frozen_importlib.BuiltinImporter'> import 'ast' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01BB09B0> # dis not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\dis.pyc' # opcode not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\opcode.pyc' import '_opcode' # <class '_frozen_importlib.BuiltinImporter'> import 'opcode' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01BD7F30> import 'dis' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01BD7570> # enum not found in PYZ import enum # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\enum.pyc # linecache not found in PYZ # tokenize not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\tokenize.pyc' # re not found in PYZ # sre_compile not found in PYZ import '_sre' # <class '_frozen_importlib.BuiltinImporter'> # sre_parse not found in PYZ # sre_constants not found in PYZ import sre_constants # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\sre_constants.pyc import sre_parse # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\sre_parse.pyc import sre_compile # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\sre_compile.pyc import '_locale' # <class '_frozen_importlib.BuiltinImporter'> # copyreg not found in PYZ import copyreg # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\copyreg.pyc import re # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\re.pyc # token not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\token.pyc' import 'token' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01C07C70> import 'tokenize' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01BDFB70> import linecache # loaded from Zip C:\Users\sou11\AppData\Local\Temp\_MEI269362\base_library.zip\linecache.pyc import 'inspect' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01B91970> [26652] LOADER: Running pyi_rth__tkinter.py [26652] LOADER: Running ブロック崩し.py # tkinter not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\tkinter\__init__.pyc' # _tkinter not found in PYZ # extension module '_tkinter' loaded from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\_tkinter.pyd' # extension module '_tkinter' executed from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\_tkinter.pyd' import '_tkinter' # <_frozen_importlib_external.ExtensionFileLoader object at 0x01D75390> # tkinter.constants not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\tkinter\constants.pyc' import 'tkinter.constants' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01D754F0> import 'tkinter' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01C220B0> # tkinter.messagebox not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\tkinter\messagebox.pyc' # tkinter.commondialog not found in PYZ # code object from 'C:\Users\sou11\AppData\Local\Temp\_MEI269362\tkinter\commondialog.pyc' import 'tkinter.commondialog' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01D80970> import 'tkinter.messagebox' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01C48190>
Rena_StarPrince

2021/11/02 13:45

長くて全部貼ることはできませんがこのようなメッセージが多く出てきます。
y_waiwai

2021/11/02 14:05 編集

うーん、出るメッセージの最後の方だけ貼ってみてください #エラーで終了するのは最後ですから
Rena_StarPrince

2021/11/02 14:08

import 'tkinter.commondialog' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01D80970> import 'tkinter.messagebox' # <_frozen_importlib_external.SourcelessFileLoader object at 0x01C48190> [26652] LOADER: OK. [26652] LOADER: Manually flushing stdout and stderr [26652] LOADER: Cleaning up Python interpreter. # clear builtins._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # clear sys.__interactivehook__ # clear sys.flags # clear sys.float_info # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup[2] removing builtins # cleanup[2] removing sys # cleanup[2] removing _frozen_importlib # cleanup[2] removing _imp # cleanup[2] removing _warnings # cleanup[2] removing _thread # cleanup[2] removing _weakref # cleanup[2] removing _frozen_importlib_external # cleanup[2] removing _io # cleanup[2] removing marshal # cleanup[2] removing nt # cleanup[2] removing winreg # cleanup[2] removing zipimport # cleanup[2] removing encodings # cleanup[2] removing codecs # cleanup[2] removing _codecs # cleanup[2] removing encodings.aliases # cleanup[2] removing encodings.utf_8 # cleanup[2] removing _signal # cleanup[2] removing __main__ # destroy __main__ # cleanup[2] removing encodings.latin_1 # cleanup[2] removing io # cleanup[2] removing abc # cleanup[2] removing _weakrefset # destroy _weakrefset # cleanup[2] removing struct # cleanup[2] removing _struct # cleanup[2] removing pyimod01_os_path # cleanup[2] removing pyimod02_archive # cleanup[2] removing zlib # cleanup[2] removing pyimod03_importers # cleanup[2] removing pyimod04_ctypes # cleanup[2] removing os # cleanup[2] removing errno # cleanup[2] removing stat # cleanup[2] removing _stat # cleanup[2] removing ntpath # cleanup[2] removing genericpath # cleanup[2] removing os.path # cleanup[2] removing _collections_abc # cleanup[2] removing pkgutil # cleanup[2] removing collections # cleanup[2] removing operator # destroy operator # cleanup[2] removing _operator # cleanup[2] removing keyword # destroy keyword # cleanup[2] removing heapq # cleanup[2] removing _heapq # cleanup[2] removing itertools # cleanup[2] removing reprlib # destroy reprlib # cleanup[2] removing _collections # cleanup[2] removing functools # cleanup[2] removing _functools # cleanup[2] removing types # cleanup[2] removing collections.abc # cleanup[2] removing weakref # destroy weakref # cleanup[2] removing importlib # cleanup[2] removing importlib._bootstrap # cleanup[2] removing importlib._bootstrap_external # cleanup[2] removing warnings # cleanup[2] removing importlib.util # cleanup[2] removing importlib.abc # cleanup[2] removing importlib.machinery # cleanup[2] removing contextlib # destroy contextlib # cleanup[2] removing inspect # cleanup[2] removing ast # cleanup[2] removing _ast # cleanup[2] removing dis # cleanup[2] removing opcode # destroy opcode # cleanup[2] removing _opcode # cleanup[2] removing enum # cleanup[2] removing linecache # cleanup[2] removing tokenize # cleanup[2] removing re # cleanup[2] removing sre_compile # cleanup[2] removing _sre # cleanup[2] removing sre_parse # cleanup[2] removing sre_constants # destroy sre_constants # cleanup[2] removing _locale # cleanup[2] removing copyreg # cleanup[2] removing token # cleanup[2] removing tkinter # cleanup[2] removing _tkinter # cleanup[2] removing tkinter.constants # cleanup[2] removing tkinter.messagebox # cleanup[2] removing tkinter.commondialog # destroy _ast # destroy _signal # cleanup[3] wiping _frozen_importlib # cleanup[3] wiping _imp # cleanup[3] wiping _warnings # cleanup[3] wiping _thread # cleanup[3] wiping _weakref # cleanup[3] wiping _frozen_importlib_external # cleanup[3] wiping _io # cleanup[3] wiping marshal # cleanup[3] wiping nt # cleanup[3] wiping winreg # destroy winreg # cleanup[3] wiping zipimport # cleanup[3] wiping encodings # destroy encodings.aliases # destroy encodings.utf_8 # destroy encodings.latin_1 # cleanup[3] wiping codecs # cleanup[3] wiping _codecs # cleanup[3] wiping io # cleanup[3] wiping abc # cleanup[3] wiping struct # cleanup[3] wiping _struct # destroy _struct # cleanup[3] wiping pyimod01_os_path # cleanup[3] wiping pyimod02_archive # destroy marshal # cleanup[3] wiping zlib # destroy zlib # cleanup[3] wiping pyimod03_importers # cleanup[3] wiping pyimod04_ctypes # cleanup[3] wiping os # destroy errno # destroy ntpath # cleanup[3] wiping stat # cleanup[3] wiping _stat # destroy _stat # cleanup[3] wiping genericpath # cleanup[3] wiping _collections_abc # cleanup[3] wiping pkgutil # destroy zipimport # cleanup[3] wiping collections # destroy _collections_abc # destroy heapq # cleanup[3] wiping _operator # cleanup[3] wiping _heapq # cleanup[3] wiping itertools # cleanup[3] wiping _collections # destroy _collections # cleanup[3] wiping functools # cleanup[3] wiping _functools # cleanup[3] wiping types # destroy collections.abc # cleanup[3] wiping importlib # destroy importlib.util # cleanup[3] wiping importlib._bootstrap # cleanup[3] wiping importlib._bootstrap_external # cleanup[3] wiping warnings # destroy _warnings # cleanup[3] wiping importlib.abc # destroy _frozen_importlib_external # destroy importlib.machinery # cleanup[3] wiping inspect # destroy ast # destroy dis # destroy importlib # destroy linecache # destroy token # cleanup[3] wiping _opcode # cleanup[3] wiping enum # destroy _functools # destroy _operator # cleanup[3] wiping tokenize # destroy io # cleanup[3] wiping re # destroy sre_compile # destroy copyreg # cleanup[3] wiping _sre # cleanup[3] wiping sre_parse # cleanup[3] wiping _locale # destroy _locale # cleanup[3] wiping tkinter # destroy tkinter.commondialog # cleanup[3] wiping _tkinter # destroy _tkinter # cleanup[3] wiping tkinter.constants # cleanup[3] wiping tkinter.messagebox # cleanup[3] wiping sys # cleanup[3] wiping builtins # destroy enum # destroy tkinter.constants # destroy re # destroy _sre # destroy sre_parse # destroy stat # destroy genericpath # destroy nt # destroy io # destroy _opcode # destroy tokenize # destroy _thread # destroy _heapq # destroy _imp # destroy importlib.abc # destroy functools # destroy types # destroy warnings # destroy _weakref # destroy collections # destroy itertools # destroy abc # destroy _frozen_importlib [26936] LOADER: Back to parent (RC: 0) [26936] LOADER: Doing cleanup
jbpb0

2021/11/03 01:55

「--debug」を付けない場合は、何て表示されるのでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問