0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pyinstallerで画像フォルダを含める

Posted at

Pythonで画像フォルダなどが存在する場合Pyinstallerでexe化するのに少し手こずったので備忘録として残します。

Pyinstaller時は以下コマンドを使用してimgフォルダ内のすべてを含める

pyinstaller --onefile --add-data "img/*;img" main.py

Pyinstallerでexe化するときに画像ファイルなどを呼びだすときに一時ファイルとして書き出されるのでその場所を特定するためのpythonコードを追加する

def resourcePath(filename):
  if hasattr(sys, "_MEIPASS"):
      return os.path.join(sys._MEIPASS, filename)
  return os.path.join(filename)

使用する際は以下の様な感じで書く

resourcePath("img/test.png")
0
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?