ImportError: No module named 'bs4' in django only
Question: The same question has been asked a number of times but I couldn't find the
solution.

After I install a package using pip, I am able to import it in python console
or python file and it works as expected. The same package when I try to
include in django, it gives `import error`. Do I need to modify `settings.py`
file or any requirement that I need to add? I am driving django with the help
of virtual env.

Eg: I am using `BeautifulSoup` and I am trying to import `from bs4 import
BeautifulSoup` and I am getting error `ImportError: No module named 'bs4'`

This error only comes in django. I am not able to figure out why this is
happening.

Screenshot attached for reference.

**1\. python console - shows no error**

[![python2 and python3
console](http://i.stack.imgur.com/exmvN.png)](http://i.stack.imgur.com/exmvN.png)

**2\. django console- import error**

[![django
console](http://i.stack.imgur.com/j0IMN.png)](http://i.stack.imgur.com/j0IMN.png)

_I am sorry as it is difficult to read the console but any other thing that I
can include which will help me make myself more clear will be appreciated._


Answer: You don't show either the code of your site or the command you ran (and the
URL you entered, if any) to trigger this issue. There's almost certainly some
difference between the Python environment on the command line and that
operating in Django.

Are you using virtual environments? If so, dependencies should be separately
added to each environment. Were you operating from a different working
directory? Python usually has the current directory somewhere in `sys.path`,
so if you changed directories it's possible you made `bs4` unavailable that
way.

At the interactive Python prompt, try

    
    
    import bs4
    bs4.__file__
    

That will tell you where `bs4` is being imported from, and might therefore
give you a clue as to why it's not available to Django.

