私はPython実行ファイルをOSX El Capitanで動かすことに取り組んでいます。Pyinstallerとcx_Freezeの両方を使って実行可能ファイルを作成すると、私は実際に別のMacで実行可能ファイルを実行します。私が得るエラーは、メインのスクリプトで参照されている.dbファイルを見つけることができないということです。そのため、両方のプログラムのドキュメントを見て、sys.MEIPASS(Pyinstaller)とsys.executable(cx_Freeze) --onefileアプリこれは私が私のメインのスクリプトで使用されるコードです:Pyinstallerの使い方 - cx_Freeze実行可能sys.MEIPASS/sys.executable
def find_data_file(filename):
if getattr(sys, 'frozen', False):
# The application is frozen
datadir = os.path.dirname(sys._MEIPASS) #in cx_Freeze this is sys.executable
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = ospath.abspath(os.pardir)
return os.path.join(datadir, filename)
#This is how im using the "find_data_file" function in my code.
dbpath = find_data_file('PubData.db')
conn = lite.connect(dbpath)
IVEは私のプロジェクトディレクトリのレイアウトに合わせて、ビットelseステートメントでそれを変更し、凍結されていないアプリケーションを実行しているとき、それは完全に正常に動作します。 しかし、ビルドされた実行ファイルを使用して実行しようとすると、sys.MEIPASSまたはsys.executableを参照していると思われる.dbファイルが見つからないというエラーが表示されます。
エラー:
Traceback (most recent call last):
File "interface/GUI.py", line 673, in <module>
File "interface/GUI.py", line 82, in __init__
File "interface/GUI.py", line 212, in getServerNames
sqlite3.OperationalError: no such table: servernames
これは私のファイルツリーがどのように見えるかです:
PubData-master ##(Project Root Directory)
Interface ##(Directory)
GUI.py ##(Main Script, this is where i reference 'PubData.db')
GUI.speC##(Pyinstaller spec file)
PubData.db ## This is my database file, in the PubData-master Directory
、誰もが私が間違っているのを教え、または私に解決策を与えることができれば、私は非常に感謝されます!