【发布时间】: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