即使已经满足要求,也没有名为selenium的模块:

时间:2019-07-09 17:29:11

标签: python selenium

我有一个奇怪的错误:

aj@vds725:~/web_scraping$ python
Python 3.6.7 (default, Oct 25 2018, 09:16:13) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aj/web_scraping/selenium.py", line 2, in <module>
    from selenium.webdriver.common.action_chains import ActionChains
ModuleNotFoundError: No module named 'selenium.webdriver'; 'selenium' is not a package

但是我已经安装了硒

aj@vds725:~/web_scraping$ pip install selenium
Requirement already satisfied: selenium in /usr/local/lib/python3.6/dist-packages (3.141.0)
Requirement already satisfied: urllib3 in /usr/local/lib/python3.6/dist-packages (from selenium) (1.24.3)

是否有可能解决此问题,为什么会发生这种情况?

1 个答案:

答案 0 :(得分:1)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aj/web_scraping/selenium.py", line 2, in <module>

问题是您已将模块命名为selenium.py,因此,当您尝试导入selenium时,它的目标是模块而不是python版本安装的selenium软件包。

出于这个原因,最好避免在其他模块/软件包之后命名模块。将/home/aj/web_scraping/selenium.py重命名为/home/aj/web_scraping/a_name_not_used_by_python.py