繁体   English   中英

没有名为“selenium.webdriver”的模块

[英]No module named 'selenium.webdriver'

我正在尝试使用 selenium 和 firefox 运行一些测试,但收到消息“ModuleNotFoundError: No module named 'selenium.webdriver'; 'selenium' is not a package”

经过研究,我尝试了各种方法,但没有任何效果。 我认为使用虚拟环境是最简单的方法,但我也无法实现。 有什么我想念的吗? 任何输入表示赞赏。

[jim@localhost Environments]$ ll ~/.local/bin/
total 8528
-rwxrwxr-x 1 jim jim     214 Sep  3 04:04 flask
-rwxrwxr-x 1 jim jim 8724590 Jan 28 17:49 geckodriver

[jim@localhost Environments]$ virtualenv -p python3.6 selenium
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/jim/Environments/selenium/bin/python3.6
Installing setuptools, pip, wheel...done.

[jim@localhost Environments]$ source selenium/bin/activate

(selenium) [jim@localhost Environments]$ which python
~/Environments/selenium/bin/python

(selenium) [jim@localhost Environments]$ ~/Environments/selenium/bin/python --version
Python 3.6.4

(selenium) [jim@localhost Environments]$ pip install selenium
Collecting selenium 
(from selenium) (1.24.1)
Installing collected packages: selenium
Successfully installed selenium-3.141.0

(selenium) [jim@localhost Environments]$ pip freeze
selenium==3.141.0
urllib3==1.24.1

(selenium) [jim@localhost Environments]$ pip show selenium
Name: selenium
Version: 3.141.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: /home/jim/Environments/selenium/lib/python3.6/site-packages
Requires: urllib3
Required-by:

(selenium) [jim@localhost Environments]$ ~/Environments/selenium/bin/python
Python 3.6.4 (default, Dec 19 2017, 14:48:12)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium.webdriver import Firefox
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jim/Environments/selenium.py", line 1, in <module>
    from selenium.webdriver import Firefox
ModuleNotFoundError: No module named 'selenium.webdriver'; 'selenium' is not 
a package

正如我所评论的,@buran 也是如此:

你在一个名为selenium的文件夹下有 python venv,它混合了导入......

正如您所展示的/home/jim/Environments/selenium/bin/python3.6看到保存 python 的bin文件夹被命名为selenium改变它,它应该可以正常工作!

您可以将其更改为类似new_selenium/home/jim/Environments/new_selenium/bin/python3.6

希望这对你有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM