2011-11-21 98 views
2

使用的Python 2.5 操作系統Windows Vista中 有一個錯誤,當我試圖使用Python和硒 - 安裝不工作

pip install -U Selenium

C:\Users\User>pip install -U Selenium 
Downloading/unpacking Selenium 
Downloading selenium-2.13.1.tar.gz (3.3Mb): 3.3Mb downloaded 
Running setup.py egg_info for package Selenium 
warning: no files found matching 'docs\api\py\index.rst' 
c:\Python25\lib\distutils\dist.py:263: UserWarning: Unknown distribution option: 'src_root' 
    warnings.warn(msg) 
Downloading/unpacking rdflib==3.1.0 (from Selenium) 
Downloading rdflib-3.1.0.tar.gz (249Kb): 249Kb downloaded 
Running setup.py egg_info for package rdflib 
Installing collected packages: Selenium, rdflib 
Found existing installation: selenium 2.13.1 
Uninstalling selenium: 
    Successfully uninstalled selenium 
Running setup.py install for Selenium 
warning: no files found matching 'docs\api\py\index.rst' 
c:\Python25\lib\distutils\dist.py:263: UserWarning: Unknown distribution option: 'src_root' 
    warnings.warn(msg) 
c:\Python25\Lib\site-packages\selenium\webdriver\remote\webdriver.py:668: Warning: 'with' will become a reserved keyword in Python 2.6 
File "c:\Python25\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 668 with open(filename, 'wb') as f: 
      ^
SyntaxError: invalid syntax 

Found existing installation: rdflib 3.1.0 
Uninstalling rdflib: 
Successfully uninstalled rdflib 
Running setup.py install for rdflib 
Successfully installed Selenium rdflib 
Cleaning up... 

人工手動下載的硒2.13包安裝硒2.13和將selenium.py文件複製到c:/ python25/lib /中。然而,當我嘗試蟒之內從進口的webdriver它給了我下面的錯誤:

C:\Users\User>python F:\Selenium\localtest2.py 
Traceback (most recent call last): 
    File "F:\Selenium\localtest2.py", line 1, in <module> 
    from selenium import webdriver 
ImportError: cannot import name webdriver 

是否存在與硒的一個問題安裝或有什麼不對勁,我在做什麼?也許只複製selenium.py文件是愚蠢的?新手,忍受我。遵循給出的教程here

在上面的教程我不知道如何做到這一點:「添加到您的測試的路徑的文件selenium.py」

回答

2

顯然,Selenium 2.13有Python 2.6的要求,給定語法錯誤(依賴:'with')。

您可以選擇在Windows計算機上安裝早期版本的Selenium,或者更好地升級到Python 2.6。

+0

你釘了它,我發佈這個問題後不久,我升級到2.7,它的工作......謝謝! – Ashwin

+0

那你不應該高興他嗎? –

2

即安裝手冊似乎有點尷尬的我。首先,刪除所有文件(嘗試pip uninstall Selenium,或者如果這不起作用,只需從site-packages文件夾中刪除selenium文件夾)。另外,請刪除您複製的單個文件selenium.py

然後,再次嘗試運行pip install -U selenium。如果你可以打開你的Python提示符並且沒有錯誤地執行以下操作,那麼你就很好。

from selenium import webdriver 

請注意,您還需要在Selenium server,安裝它,如下所示:

java -jar selenium-server-standalone-2.13.0.jar 

如果這一切都沒有工作,因爲之前清理您的站點包,只是下載和安裝在Python package index上找到的文件。解壓後,打開提取文件的命令提示符並運行python setup.py install。然後,如上所述再次嘗試從命令提示符處導入硒。