Pipenv modules not found

Question:

I installed pipenv and then used pipenv install beautifulsoup4. My understanding is that this should have created a pipfile and a virtual env. So I started up pipenv shell. My pipfile is there, with Beautiful Soup there. Next thing I tried to do was pipenv install selenium. I wrote this really short script:

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Firefox()
profile = 'https://www.linkedin.com/in/user-profile-name'

driver.get(profile)

html = driver.page_source

soup = BeautifulSoup(html)

print(soup)

I tried running it and got this error:

Traceback (most recent call last):
  File "LiScrape.py", line 2, in <module>
    from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

I tried running python3 in the shell and just doing import selenium to see if it would let me check the version. Again, I got the ModuleNotFoundError.

What am I doing wrong with selenium that I didn’t do wrong with beautiful soup??

Asked By: bkula

||

Answers:

You just need to activate the virtual environment created by pipenv either by:

$ pipenv run python foo.py

or:

$ pipenv shell
> python foo.py

The whole process for reference:

$ pipenv --python 3.6.4 install beautifulsoup4 selenium
$ echo "import bs4 ; import selenium" > foo.py
$ pipenv run python foo.py

Or whatever version of Python you prefer.

(You should see no errors.)

This works for me.

Answered By: Taylor D. Edmiston