我在MacOS上运行的是Python3.9.3中的selenium-stealth。
当我使用PyInstaller ( pyinstaller --noconfirm --onefile --console --hidden-import "cmath" "/Users/name/Downloads/AmazonSellerCentral/main.py")构建应用程序时,我得到以下错误:
Traceback (most recent call last):
File "main.py", line 141, in <module>
File "main.py", line 77, in create_driver
File "selenium_stealth/__init__.py", line 45, in stealth
File "selenium_stealth/utils.py", line 8, in with_utils
File "pathlib.py", line 1255, in read_text
File "pathlib.py", line 1241, in open
File "pathlib.py", line 1109, in _opener
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/7z/3spcsmdx5n344dh0fb5j0hl40000gn/T/_MEIqfmicz/selenium_stealth/js/utils.js'。
不过,只需运行python3 main.py就可以了。
重新安装selenium-隐形没有做任何事情,我不确定我可以尝试从这里修复/更改什么?
发布于 2021-04-08 10:48:04
快速周转(问题请参考我在评论部分的评论):
步骤1:构建包,请参考代码部分中的命令)
步骤2:创建文件夹--> dist\your package(在我的例子中是slhpackage)\selenium_stealth\js
步骤3-从https://github.com/diprajpatra/selenium-stealth/tree/main/selenium_stealth/js复制js文件,并将其放入在步骤2中创建的文件夹中。
现在你的可执行文件应该运行的很好了。
pyinstaller slhpackage.py # build package (1)#Python version ==> Python: 3.9.2 (conda)发布于 2021-04-19 21:21:09
我使用的是Python 3.9,今天遇到了同样的问题。正如@simpleApp所说,我遵循了同样的原则,只做了最少的修改,到目前为止,它对我来说是有效的。
按照以下给定步骤进行操作:
确保您复制了.
folder_name(might be anthing you wish)/selenium_stealth/js中的所有文件。确保您的名称selenium_stealth/js不做任何修改,否则您将面临conflicts.
为了方便起见,我在这里添加了它,这样不仅对您,而且对所有使用它的人来说都更容易。
pyinstaller --noconfirm --onefile --console --icon "dir:\path\to\icon.ico" --add-data "dir:\path\to\folder_name\mentioned\above;." --add-binary "dir:/path/to/chromedriver/chromedriver.exe;./selenium/webdriver" "dir:/path/to/your/python/file.py"复制代码,根据您的文件路径修改它(我已经给出了通用名称)。我建议您制作一个.bat文件,以便将代码粘贴到该文件中以备将来使用。
下面是我的代码片段:
@ECHO OFF
color 09
echo Immediate direct Conversion of .py to .exe standalone by PiXinCreate
echo.
pyinstaller --noconfirm --onefile --console --icon "dir:\path\to\icon.ico" --add-data "dir:\path\to\folder_name\mentioned\above;." --add-binary "dir:/path/to/chromedriver/chromedriver.exe;./selenium/webdriver" "dir:/path/to/your/python/file.py"
echo.
echo .exe has been successfully created for .py
echo.
pause.
exit发布于 2021-04-07 22:48:21
您看到的错误表明文件的路径可能有问题。
确保文件utils.js存在于它试图定位的路径中。
如果没有,您可以尝试从外部下载它,并将其放入该路径中。不过,我不认为这是一个好的建议。
https://stackoverflow.com/questions/66924822
复制相似问题