简体   繁体   English

在 pyinstaller 中添加 pip 库以为我的脚本创建 exe 文件

[英]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.我可以运行我的 exe 文件,但我的脚本有多个 pip 库可以运行。 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".看来您的脚本/exe 正在寻找一个名为“browsers.json”的文件。 Locate it and try putting it in the same folder as your created *.exe找到它并尝试将其放在与您创建的 *.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如果这不起作用 pip 在终端中安装 cloudcraper 代替,因为 pycharms 将文件分配给它自己的环境

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.似乎您的browswers.json 预计会在“exe”(cloudscraper/user_agent)的相对路径中找到,而实际上它不是一个exe文件。 You have to modify your pyinstaller build command to include that file in the package.您必须修改 pyinstaller 构建命令以将该文件包含在 package 中。 Add --add-data '/lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json:cloudscraper/user_agent' and it should work.添加 --add-data '/lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json:cloudscraper/user_agent' 它应该可以工作。 (replace: with; on Windows) (替换:用;在 Windows 上)

You can refer to https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files for more details.您可以参考https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files了解更多详情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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