将python脚本转换为exe时出错

时间:2015-03-02 11:45:57

标签: python windows firefox selenium py2exe

我在Windows 7 x86_64系统上使用Python 3.4.1,我有一个脚本,通过使用我编写过python脚本的“Firefox”Web浏览器自动从网站下载一些数据转储。

在我导入的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”作为业余爱好者。

谢谢!

1 个答案:

答案 0 :(得分:0)

好吧,错误说程序无法在C:\My_Project\dist\library.zip\selenium\webdriver\firefox\webdriver_prefs.json

中找到该文件

你确定它所寻找的目录和文件在那里吗?

相关问题