0

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.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

3 Answers3

2

Check this link: https://stackoverflow.com/a/64586862/14509818

or

Add this command while creating your exe.

--add-data "path_for_cloudscraper_folder;./cloudscraper/"

Replace path_for_cloudscraper_folder with the path of your cloudscraper folder.

You can explore and find your path of cloudscraper folder from pc or dowload it from github.

Here ./cloudscraper/ is used to add cloudscraper folder in your root directory of output. (expecting that it is searching in root directory for missing cloudscraper folder)

0

Your .exe file is looking for browsers.json, but you didn't move that file to the same path as the .exe file. Working with pyinstaller requires good experience handling relative and absolute paths, otherwise, you will face that kind of errors.

If cloudscraper is not part of your project tree (maybe is a hidden import):

  1. Try copy the folder named 'cloudscrapper' from here and paste it in the same path of your .exe file
ljuk
  • 701
  • 3
  • 12
0

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