Search code examples
pythonpython-3.xpyinstaller

Error creating .exe (pyinstaller) with cloudscraper module


I'm trying to create an .exe from my python script. The script uses the cloudscraper package. When I create the .exe and I execute it, it shows the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\...\\MEI1....\\cloudscraper\\user_agent\\browsers.json'

The error ONLY APPEARS WHEN I TRY TO EXECUTE THE .exe file.

Why is this happening? Is cloudscraper unavailable with pyinstaller?

The project structure looks like this:

C:\Users\andre\OneDrive\Documentos\Programming\Python\Python3\proyect

proyect 
   |
   |______ main.py
   |
   |______ services
           |________ __init__.py
           |_______ main_service.py
           |_______ sql_service.py

This is very similar to my project structure since obviously, I cannot share the actual project structure of my project.


Solution

  • The found solution is to copy the required folder inside the .exe path but as for now a days, I found that this could not be achieved if you're using the --onefile modifier to create the .exe, instead you should not use it and copy the cloudscraper folder inside such .exe path, and that should work

    NOTE: The path is NOT THE PARENT FOLDER cloudscraper, instead is the nested folder which in it has the user_agent folder