1

So I'm getting an import error on this line:

from bs4 import BeautifulSoup

It says:

ImportError: no module named 'bs4'

Any idea what's going on / how to fix this?

Thanks, Mariogs

anon_swe
  • 6,941
  • 14
  • 68
  • 115
  • Not totally sure what's going on here re: comments. Link says there are two comments but I can't view any... – anon_swe Mar 22 '14 at 02:38
  • This means that you didn't install bs4, so you have to install it http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-beautiful-soup – Tymoteusz Paul Mar 22 '14 at 02:43
  • Well I did that and got this back: Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.3.2-py2.7.egg Cleaning up... – anon_swe Mar 22 '14 at 02:51
  • @puciek, please see above! – anon_swe Mar 22 '14 at 03:12
  • Are you using an IDE? It may be selecting a different python instance than the one where you installed bs4 to. Also, after installing a packing, make sure to close out of and re-open any python interpreters. – CasualDemon Mar 22 '14 at 03:12
  • no ide, just vim. python interpreters? i'm just using iterm... – anon_swe Mar 22 '14 at 03:23
  • There are probably several python installation on your machine. Print `sys.path` to see what paths are used to look for Python modules – jfs Mar 22 '14 at 05:32

1 Answers1

0

import sys; print(sys.path) shows that you use Python 3.3 but the output from pip shows that it installs for Python 2.7

Use pip that installs for Python 3.3. It might be already installed as pip3 or pip3.3. If not; then install it first.

Community
  • 1
  • 1
jfs
  • 346,887
  • 152
  • 868
  • 1,518
  • so I get to this page: https://raw.github.com/pypa/pip/master/contrib/get-pip.py and have 0 idea what to do with it...mind providing a bit of guidance? Thanks again for all your help! – anon_swe Mar 23 '14 at 22:34
  • @Mariogs: [how to install pip for python3 on mac os x](http://stackoverflow.com/q/20082935/4279) – jfs Mar 23 '14 at 22:36
  • Ah ok, just followed that. No error messages when installing pip for python3. I still have the "requirement already satisfied" message when I run 'pip install beautifulsoup4'. What am I missing? Thanks again – anon_swe Mar 23 '14 at 23:23
  • @Mariogs: do you understand that there may be *two* different `pip` scripts on your system? Create a symlink named `pip3` if it does not already exist for the `pip` that you installed for Python 3.3 – jfs Mar 24 '14 at 06:07
  • Yes, I get that. By "symlink" do you mean an alias in my bash profile? I'm not exactly sure how to specify one for the pip I installed for Python 3.3 – anon_swe Mar 24 '14 at 15:42
  • @Mariogs: what happens if you put "symlink" in google – jfs Mar 24 '14 at 15:55
  • Looks like they're the same as aliases on Mac. I think my confusion is this: if I create an alias named 'pip3', what string am I setting that equal to in order to access the pip I installed for Python 3? – anon_swe Mar 24 '14 at 17:05
  • @Mariogs: symlink is not an alias. Look for `ln -s` command in [the installation instructions linked above](http://stackoverflow.com/q/20082935/4279). Run `which pip` and see if it gives you any ideas about the Python version (look for 2.7 and 3.3 in the path). Or run `head -1 $(which pip)` to see the shebang. – jfs Mar 24 '14 at 18:20