Python not detecting existing modules

Viewed 130

Trying to run a .py file on Kali Linux using:

`sudo python2 test.py`

I get the error message:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    import selenium
ImportError: No module named selenium

The problem is that selenium is already installed, when pip is asked to install selenium this error message is shown:

sudo pip3 install selenium     

I get this message:

Requirement already satisfied: selenium in /usr/lib/python3/dist-packages (4.0.0a1)

What should I do? I guess that it is related to pip2, but I cant install it. Please help me. This the file's code:

import sys 
import datetime 
import selenium import requests 
import time as t from sys 
import stdout from selenium 
import webdriver from optparse 
import OptionParser
1 Answers

There are multiple different versions of python on your system. The file you are running is with the python2 interpreter. pip3 is a package manager for python3.

If you want to see all your installed versions of python you can run ls /usr/bin/python* (just ignore python-config and pythonw directories). To install selenium on python2 you need to use pip instead of pip3. Alternatively, you can try running that file with python3 since it doesn't look like there are any python2 print statements, xrange, etc. which might cause python3 to fail.

Related