[英]Error creating .exe (pyinstaller) with cloudscraper module
I'm trying to create an.exe from my python script.我正在尝试从我的 python 脚本创建 an.exe。 The script uses the cloudscraper package.
该脚本使用cloudscraper package。 When I create the.exe and I execute it, it shows the following error:
当我创建 .exe 并执行它时,它显示以下错误:
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.该错误仅在我尝试执行该.exe 文件时出现。
Why is this happening?为什么会这样? Is cloudscraper unavailable with pyinstaller?
pyinstaller 无法使用 cloudcraper 吗?
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.这与我的项目结构非常相似,因为很明显,我无法分享我项目的实际项目结构。
Check this link: https://stackoverflow.com/a/64586862/14509818检查此链接: https://stackoverflow.com/a/64586862/14509818
or或者
Add this command while creating your exe.在创建 exe 时添加此命令。
--add-data "path_for_cloudscraper_folder;./cloudscraper/"
Replace path_for_cloudscraper_folder with the path of your cloudscraper folder.将path_for_cloudscraper_folder替换为您的 cloudscraper 文件夹的路径。
You can explore and find your path of cloudscraper folder from pc or dowload it from github.您可以从 PC 浏览并找到您的 cloudcraper 文件夹路径,或从 github 下载。
Here ./cloudscraper/ is used to add cloudscraper folder in your root directory of output.这里./cloudscraper/用于在 output 的根目录下添加 cloudscraper 文件夹。 (expecting that it is searching in root directory for missing cloudscraper folder)
(期望它在根目录中搜索丢失的 cloudcraper 文件夹)
Your.exe file is looking for browsers.json, but you didn't move that file to the same path as the.exe file.您的 .exe 文件正在寻找 browsers.json,但您没有将该文件移动到与 .exe 文件相同的路径。 Working with pyinstaller requires good experience handling relative and absolute paths, otherwise, you will face that kind of errors.
使用 pyinstaller 需要有处理相对路径和绝对路径的良好经验,否则,您将面临此类错误。
If cloudscraper is not part of your project tree (maybe is a hidden import):如果 cloudcraper 不是您的项目树的一部分(可能是隐藏的导入):
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找到的解决方案是将所需的文件夹复制到 .exe 路径中,但就目前而言,我发现如果您使用
--onefile
修饰符创建 .exe ,则无法实现,而不是您不应该使用它并在such.exe路径中复制cloudscraper文件夹,这应该可以
NOTE: The path is NOT THE PARENT FOLDER cloudscraper , instead is the nested folder which in it has the user_agent
folder注意:路径不是父文件夹 cloudcraper ,而是嵌套文件夹,其中包含
user_agent
文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.