【问题标题】:Error converting python script to exe将python脚本转换为exe时出错
【发布时间】:2015-03-02 11:45:57
【问题描述】:

我在 Windows 7 x86_64 系统上使用 Python 3.4.1,并且我有一个脚本,它使用“Firefox”网络浏览器自动从网站下载一些数据转储,为此我编写了一个 python 脚本。

在我正在导入的 python 脚本中:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import os

我还使用以下脚本从脚本中调用“.bat”文件:

os.system("C:\\some_user\\Test1.bat")

我现在想为此创建一个“.exe”文件,这样它就可以分发到许多机器上,而无需安装“Python”或“Selenium”。

我正在使用以下“setup.py”文件:

from distutils.core import setup
import py2exe

setup(console=['Get_Data.py'])

其中“Get_Data.py”是要转换为exe文件的脚本。

当我执行命令时:

C:\My_Project>python3 setup.py py2exe

我得到了输出:

running py2exe

  3 missing Modules
  ------------------
? readline                            imported from cmd, code, pdb
? win32api                            imported from platform
? win32con                            imported from platform
Building 'dist\New_HPSM_Tool.exe'.
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd

当我转到 C:\My_Project 中的“dist”文件夹并执行“Get_Data.exe”时,我得到以下输出:

Traceback (most recent call last):
  File "Get_Data.py", line 11, in <module>
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 43, in __init__
    self.profile = FirefoxProfile()
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile
.py", line 64, in __init__
    WEBDRIVER_PREFERENCES)) as default_prefs:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\My_Project\\dist\\library.zip\\selenium\\webdriver\\firefox\\webdriver_prefs.jso
n'

如何获取 exe 文件。我作为业余爱好者使用“py2exe”。

谢谢!

【问题讨论】:

    标签: python windows firefox selenium py2exe


    【解决方案1】:

    嗯,错误说程序在C:\My_Project\dist\library.zip\selenium\webdriver\firefox\webdriver_prefs.json中找不到文件

    您确定要查找的目录和文件在那里吗?

    【讨论】:

    • 是的,该目录确实存在。但不是名为 "webdriver_prefs.json" 的文件,而是一个文件 "webdriver.pyc"。接下来我该怎么办?
    • 视情况而定。如果该文件是您要查找的文件,则只需修改代码以使用该文件。否则,您将不得不在另一个目录中查找,或者在 Internet 上找到该文件。
    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    相关资源
    最近更新 更多