简体   繁体   中英

Adding pip libraries in pyinstaller to create an exe file for my script

I am able to run my exe file but my scripts has multiple pip libraries for it to work. I always get this error when running my script.

Exception in thread Thread-1:
Traceback (most recent call last):
  File "threading.py", line 932, in _bootstrap_inner
  File "threading.py", line 870, in run
  File "AIO_Bot.py", line 265, in main_function
  File "cloudscraper/__init__.py", line 665, in create_scraper
  File "cloudscraper/__init__.py", line 120, in __init__
  File "cloudscraper/user_agent/__init__.py", line 20, in __init__
  File "cloudscraper/user_agent/__init__.py", line 77, in loadUserAgent
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/8g/gkf53znx7_7405c26w344ftw0000gn/T/_MEIujM2ll/cloudscraper/user_agent/browsers.json'
Finished in 0.0 second(s)

If anyone knows how to fix this please help!

It seems your script/exe is looking for a file named "browsers.json". Locate it and try putting it in the same folder as your created *.exe

The file is not being located because you are searching through a path that can not be opened. If your script is on the same level of the path then you would only have to do this

(browsers.json)

to fix this just exclude the directory path

mv /lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json /var/folders/8g/gkf53znx7_7405c26w344ftw0000gn/T/_MEIujM2ll/cloudscraper/user_agent/

if this does not work pip install cloudscraper in terminal instead because pycharms assigniing the file to it's own enviroment

It seems that your browswers.json is expected to be found in a relative path from the "exe" (cloudscraper/user_agent) when it is not the case when it is really a exe file. You have to modify your pyinstaller build command to include that file in the package. Add --add-data '/lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json:cloudscraper/user_agent' and it should work. (replace: with; on Windows)

You can refer to https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files for more details.

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