猿问

我们是否需要在每次使用 Python 打开和执行新项目时安装 Selenium?

我在 python 项目中安装了 selenium 和 chrome 驱动程序,当我创建一个新项目时说它无法识别 selenium 模块。

这是否意味着我需要在每个项目中再次安装 selenium?


守候你守候我
浏览 273回答 4
4回答

慕仙森

不,您不需要为每个项目安装Selenium。安装过程一生只有一次,通过命令行界面使用以下任一命令:使用点:pip install selenium使用pip3:pip3 install selenium升级点子但是,您需要继续定期升级 pip :在Linux或者苹果系统:pip install -U pip在视窗:python -m pip install -U pip或者C:\Users\username>python -m pip install --upgrade pipCollecting pip  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)  100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.3MB 544kB/sInstalling collected packages: pip  Found existing installation: pip 10.0.1    Uninstalling pip-10.0.1:      Successfully uninstalled pip-10.0.1Successfully installed pip-18.0升级硒作为一项强制措施,您需要升级Selenium绑定以与每个稳定版本的发布保持同步,如下所示:C:\Users\username>pip install -U seleniumCollecting selenium  Downloading https://files.pythonhosted.org/packages/b8/53/9cafbb616d20c7624ff31bcabd82e5cc9823206267664e68aa8acdde4629/selenium-3.14.0-py2.py3-none-any.whl (898kB)    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 901kB 380kB/sRequirement not upgraded as not directly required: urllib3 in c:\python\lib\site-packages (from selenium) (1.22)Installing collected packages: selenium  Found existing installation: selenium 3.12.0    Uninstalling selenium-3.12.0:      Successfully uninstalled selenium-3.12.0Successfully installed selenium-3.14.0You are using pip version 10.0.1, however version 18.0 is available.You should consider upgrading via the 'python -m pip install --upgrade pip' command.

呼啦一阵风

是的,你需要。在为每个项目创建虚拟环境的情况下。最好将它安装到项目虚拟环境中。这将为您在以后调试代码时省去很多压力。

SMILET

您不需要每次都需要,您需要通过提供路径和定位到您机器中的文件夹来使用

烙印99

每次尝试运行自动化测试时,都需要在 selenium 中初始化浏览器。driver = webdriver.Chrome('./chromedriver')driver.get("https://www.python.org")print(driver.title)当您尝试从不同的项目运行测试时,您不需要每次都需要初始化浏览器会话时安装 selenium。也使用pip to installselenium 包。安装 python 后,尝试使用以下命令使用 pip 命令安装 seleniumpip install selenium您会在下面找到您的依赖项Python\Lib\site-packages
随时随地看视频慕课网APP

相关分类

Python
我要回答