LoginSignup
1
0

More than 3 years have passed since last update.

pyinstaller にで作成した exeでNo such file or directory問題

Last updated at Posted at 2020-04-03

実行すると No such file or directory

ファイルのパスがExeで解凍されると違う場所になるので、パスを解凍後のパスに設定する必要がある

application_path = (
    sys._MEIPASS
    if getattr(sys, "frozen", False)
    else os.path.dirname(os.path.abspath(__file__))
)

このapplication_pathをファイルに付け加える必要がある

# 修正前
driver = webdriver.Chrome('chromedriver', options=options)
# 修正後
driver = webdriver.Chrome(application_path + '/chromedriver', options=options)

開発中は修正前でも動くの忘れがち

おまけ

exeが置いてあるパスを取りたい時

os.path.dirname(sys.argv[0])
1
0
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
1
0