1

I know this is a common issue but I still can't figure how to make it work. I'm trying to use bs4 inside a virtual environment but I have this error ImportError: No module named 'bs4'

I have my virtualenv activated :

pip install bs4
Requirement already satisfied: bs4 in /home/****/.virtualenvs/****/lib/python3.5/dist-packages
Requirement already satisfied: beautifulsoup4 in /home/****/.virtualenvs/****/lib/python3.5/dist-packages (from bs4)

My scripts start with

!/usr/bin/python3.5 
# -*-coding:Utf-8 -*
import json
import hashlib
from bs4 import BeautifulSoup

Any help is welcome !

RogerFromSpace
  • 406
  • 4
  • 17

1 Answers1

3

Are you sure you are using the right python? If you have everything tied up in a virtual environment, then you need to be using python from inside that virtualenv. The command:

which python

at a bash prompt should tell you what the command:

python

points to. From the look of your script, you are asking it to go to /usr/bin/python3.5, which is not the directory of your virtualenv, by looking at your path, it is somewhere in your home directory. Try changing the path in your script to the python virtualenv version (the one which pip has found bs4 in).

Nick H
  • 1,081
  • 8
  • 13