webdriverprefs.json找不到pyins

2024-04-20 13:14:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用selenium包的python程序,当使用pyinstaller从这个程序创建一个exe时,它会正确地创建exe。尝试从此应用程序打开firefox时,出现以下错误:

IOError: [Errno 2] No such file or directory:
'C:\\users\\mohamed\\Temp\\_MEI622\\selenium\\webdriver\\firefox\\webdriver_prefs.json'

我找到了这个解决方案,但它对我无效:

Py2exe isn't copying webdriver_prefs.json into builds

有什么想法吗?在


Tags: no程序json应用程序selenium错误firefoxexe
3条回答

根据我的经验,pyinstaller在创建可执行文件时总是把事情搞砸。我建议您改用py2exe。在

只需将这些(.json&;.xpi)文件作为任意文件包含在.spec文件中。在

以下是对我有效的方法(您可能需要更改路径):

needed_selenium_files = [(r'selenium\webdriver\firefox\webdriver_prefs.json',
                           r'C:\Anaconda\Lib\site-packages\selenium\webdriver\firefox\webdriver_prefs.json',
                          'DATA'),
                         (r'selenium\webdriver\firefox\webdriver.xpi',        
                           r'C:\Anaconda\Lib\site-packages\selenium\webdriver\firefox\webdriver.xpi',
                           'DATA')]

后来:

^{pr2}$

阅读PyInstaller手册的更多信息: http://pythonhosted.org/PyInstaller/#toc-class-table-of-contentshttp://pythonhosted.org/PyInstaller/#adding-files-to-the-bundle

我找到了解决办法, 当将脚本冻结到exe时,不要使用onefile,而是使用onedir,它将为所有文件生成一个文件夹,然后将路径c:\python27\lib\site packages\selenium中的selenium文件夹复制到应用程序文件夹中,它可以正常工作

相关问题 更多 >