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

时间:2019-02-04 15:11:39

标签: python selenium selenium-webdriver pip virtualenv

我正在尝试使用selenium和firefox运行一些测试,并且收到消息“ ModuleNotFoundError:没有名为'selenium.webdriver'的模块;'selenium'不是软件包”

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

[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

1 个答案:

答案 0 :(得分:1)

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

您在名为<br/>的文件夹下有python venv,该文件夹混合了导入内容...

如您所显示的selenium所示,将存放该Python的/home/jim/Environments/selenium/bin/python3.6文件夹命名为bin,它应该可以正常工作!

您可以将其更改为seleniumnew_selenium

希望这对您有帮助!