2015-03-02 38 views
0

我在Windows 7 x86_64系統上使用Python 3.4.1,我有一個腳本可以通過使用「Firefox」web瀏覽器自動從網站下載一些數據轉儲, 。將python腳本轉換爲exe時出錯

內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 

我也是從使用腳本中調用一個「蝙蝠」文件:

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之內爲 「DIST」 文件夾:\ MY_PROJECT和執行 「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」作爲業餘愛好者。

謝謝!

回答

0

那麼,錯誤說,該程序無法找到C:\My_Project\dist\library.zip\selenium\webdriver\firefox\webdriver_prefs.json

文件確定的目錄,它是要找的文件是嗎?

+0

是的目錄確實存在。但不是名爲**「webdriver_prefs.json」**的文件,而是一個**「webdriver.pyc」**文件。接下來我應該做什麼? – Arun 2015-03-18 06:43:32

+0

這取決於。如果該文件是您正在尋找的文件,那麼只需修改代碼即可使用該文件。否則,您將不得不查看另一個目錄或者可能在互聯網上找到該文件。 – 2015-03-18 17:47:22

相關問題