简体   繁体   中英

Cannot open an exe file

import extruct 

def main():
    input("Hello")

if __name__ == '__main__':
    main()

This is the code that I converted into an exe file with pyinstaller. If I open this file now, the exe crashes directly. At the bottom is the message:

FileNotFoundError: [WinError 3] The system cannot find the specified path: 'C:\Users\test\AppData\Local\Temp\_MEI801802\mf2py\backcompat-rules'"


It is definitely because I am importing "extruct". But I need this library for the correct code. Does anyone know how I can fix this error?

I got it to work... these are the steps I took. Im using windows. On another operating system the only changes that need to be made are the virtual environment path to the bakcompat-rules directory.

  1. create a new empty directory and copy and paste your code into main.py file
  2. py -m venv venv
  3. venv/Scripts/activate
  4. py -m pip install --upgrade pip pyinstaller extruct
  5. pyinstaller -F main.py
  6. This will create a main.spec file. open it and at the top paste the following
import os
data = []
parent = "./venv/Lib/site-packages/mf2py/backcompat-rules/"
for item in os.listdir(parent):
    path = os.path.join(parent, item)
    target = parent
    data.append((path, "mf2py/backcompat-rules"))
  1. in same file in Analysis signature change datas=[], to datas=data,
  2. pyinstaller main.spec
  3. dist/main.exe

And it should run fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM