[英]Changing Selenium from Py3 to Py2
I installed a Selenium server using Python 3.6. 我使用Python 3.6安装了Selenium服务器。 However, I found that the tests I am working on are written in Python2.
但是,我发现我正在使用的测试是用Python2编写的。 My shop has asked me to change my Selenium installation so that it can process Python2 code, but I have been unable to successfully make the change.
我的商店要求我更改Selenium安装,以便它可以处理Python2代码,但是我无法成功进行更改。
I have installed Python 2.7.10 and have changed the Windows path to the new Py2. 我已经安装了Python 2.7.10,并将Windows路径更改为新的Py2。 I have tried re-downloading the Selenium server, to no avail.
我尝试重新下载Selenium服务器,但无济于事。 I have also tried
pip install selenium
in a Py2 environment, and have confirmed the files are in my C:/Python27 folder. 我还尝试在Py2环境中
pip install selenium
,并确认文件在我的C:/ Python27文件夹中。 Even with the OS pointed at Python 2, Selenium remains pointed at Python 3. How can I change Selenium to run Python2 code instead of Python3? 即使操作系统指向Python 2,Selenium仍然指向Python3。如何更改Selenium以运行Python2代码而不是Python3?
OS: Win10-64bit 操作系统:Win10-64bit
Python: 2.7.10 (formerly 3.6) Python:2.7.10(以前为3.6)
On the first line of your Python 3.5 code, as this line: 在Python 3.5代码的第一行,如下所示:
from __future__ import print_function, division
This will take care of two main differences between Python 3.5 and Python 2.7. 这将解决Python 3.5和Python 2.7之间的两个主要区别。 There are other s that could be imported to improve compatibility.
可以导入其他来提高兼容性。
and if you want to add the path: 如果要添加路径:
Add python's path to the end of the list (the paths are separated by semicolons). 将python的路径添加到列表的末尾(路径以分号分隔)。 For example:
例如:
C:\\Windows;C:\\Windows\\System32;C:\\Python27 C:\\ WINDOWS; C:\\ Windows \\ System32下; C:\\ Python27
The Selenium files were installed in my local Python36 folder. Selenium文件安装在我的本地Python36文件夹中。 After removing all Selenium files from the Python36 folder, I reinstalled Selenium using the .whl files provided at https://pypi.python.org/pypi/selenium (download, then extract and install using
pip install <filename>.whl
) and ensured the extracted and installed files were in my /Python27 folder. 从Python36文件夹中删除所有Selenium文件后,我使用https://pypi.python.org/pypi/selenium中提供的.whl文件重新安装了Selenium(下载,然后使用
pip install <filename>.whl
提取并安装),然后确保提取和安装的文件在我的/ Python27文件夹中。
This, coupled with a similar procedure for nosetests (shell program used to perform my testing), reset Selenium to execute Python2 code. 加上类似的鼻子测试程序(用于执行我的测试的shell程序),将Selenium重置为执行Python2代码。 If anyone has a more elegant solution, please share.
如果有人有更好的解决方案,请分享。 Until then, I hope this helps the next poor soul who has to deal with this.
在此之前,我希望这能帮助下一个必须解决的下一个可怜的灵魂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.