0

I'm trying to build an easy python (python3) web scraper on a Mac. I installed Selenium in many different ways but always when I run my web scraping program the output says:

Traceback (most recent call last):
  File "/Users/username/Desktop/instagram_bot.py", line 1, in <module>
    from selenium import webdriver
ImportError: No module named selenium
[Finished in 0.6s with exit code 1]
[shell_cmd: python -u "/Users/username/Desktop/instagram_bot.py"]
[dir: /Users/username/Desktop]
[path:       /Users/username/opt/anaconda3/bin:/Users/username/opt/anaconda3/condabin:/Users/username/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

This is a common question but I have not found a solution yet.

tcffm
  • 139
  • 2
  • 9
  • Always share the entire error message/traceback. We need some information on your environment. From looking at the other comments in here, if you're struggling with this I would recommend just using Conda. – AMC Jan 25 '20 at 19:24
  • Now I uploaded the whole error message – tcffm Jan 25 '20 at 19:37
  • It could be you have multiple Python versions installed - so `pip install` will not install to the conda version. Maybe try `conda install` ([see here for more info](https://docs.anaconda.com/anaconda/user-guide/tasks/install-packages/)) – user101 Jan 25 '20 at 19:41
  • 1
    Ooh you were already using Conda. Can you share how you installed Selenium? My guess is that it was improperly installed, or the virtual environment is not being used. – AMC Jan 25 '20 at 19:42
  • @user101 Actually, Conda environments come with their own version of pip, so they technically could do `pip install`, although they really shouldn't. Then their's the whole issue of installing it in the correct environment ;) – AMC Jan 25 '20 at 19:44
  • I installed Selenium with pip3 (pip3 install selenium) because I usually don't use Anaconda – tcffm Jan 25 '20 at 19:45
  • actually I'm using Sublime Text.. I'm so confused about all the files and packages I have on my Computer right now :( How can I check if I'm using the virtual env correctly? – tcffm Jan 25 '20 at 19:53
  • @tcffm _because I usually don't use Anaconda_ ...2 minutes later... _I'm so confused about all the files and packages I have on my Computer right now :(_ ;p – AMC Jan 25 '20 at 20:52
  • _How can I check if I'm using the virtual env correctly?_ What do you mean? You should check out the [Conda docs](https://docs.conda.io/en/latest/), they're pretty decent in my experience. You've told us very little about your environment, can you say more _about all the files and packages_ ? – AMC Jan 25 '20 at 20:53
  • I have different virtual environments. One is the environment called venv which I have created for the new project. In that environment I've installed Selenium and Pip. But when I run the code after activating venv the error I've postet above shows up. It seems like the the Program I'm working on doesn't even search in that environment. – tcffm Jan 25 '20 at 23:51

2 Answers2

0

Selenium package is not installed correctly.

If you have pip installed you can install selenium like so.

Windows:

pip install selenium

Unix:

sudo pip install selenium
Muzzamil
  • 2,823
  • 2
  • 11
  • 23
0

Probably you have more than one python installation.

You can install a module using your current python installation in the following way:

python -m pip install --user --upgrade --no-cache selenium
alessiosavi
  • 2,753
  • 2
  • 19
  • 38