Flask built with Pyinstaller cannot find files in folder

Viewed 97

I have built a web application with flask (script.py) that is supposed to do some work with some files. Now the folder structure goes like this:

|
|->script.py
|
└───files
    |
    └───src

The user places manually some files in the files folder. The flask app uses static files(index.html, js, favicon) from the src folder located inside the files folder.

The user can request any file located in the files folder and subfolder hitting its name like 127.0.0.1/file.txt and flask replies with this file using this piece of code:

@app.route('/<path:path>')
def send_js(path):
    return send_from_directory('files', path)

The appilication works properly in python but not working when I build script.py with PyInstaller. In order to build the application I used this command:

pyinstaller -F --add-data "files;files" script.py

In particular, it is able to serve all static files in the src folder, but unable find any other file that was not included in the build of the executable. This means flask logs a 404 http code in the console when the user requests a file that he wants to work with, other than the static files. What is weird is that other functions and libraries inside script.py not related to flask code flow, have no difficulty locating the user files and doing stuff with them.

I did a lot of research and did not manage to crack it down.

Any suggestions?

Thank you

*System specs*
 Windows 10 pro 64bit
 Python 3.9
 Flask 2.0.2
 pyinstaller 4.7
0 Answers
Related