0

I am completely new to all things programming. As I am working to learn the basics of Python, I have run into a problem that I've been unable to work through by reading and Googling.

I am trying to install BeautifulSoup, and I thought I had done so successfully, but when I try to test whether or not it's installed correctly I get an error.

I am using PyCharm and typed the following into the Python Console:

>>> from bs4 import BeautifulSoup

And I receive the following error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'bs4'

I read through a previous thread about a BeautifulSoup install error and one of the things that was mentioned was to check the preferences settings in PyCharm to ensure that it's using the right version of Python . . .

PyCharm Project Interpreter Screenshot

Anyway, I can't seem to figure out what's wrong, so any insight and help in resolving this issue would be tremendously appreciated.

DuncanKinnear
  • 4,563
  • 2
  • 34
  • 65
tforbes
  • 1
  • 2
  • using virtualenv? – Alex Sep 21 '16 at 21:54
  • Describe how you installed BeautifulSoup please? – Danielle M. Sep 21 '16 at 21:54
  • @DanielleM. Thank you for getting back to me. I installed it by downloading (beautifulsoup4-4.5.1) from crummy.com. Then I unzipped the folder and in terminal typed cd (then the location of the folder contents), then in terminal again I typed sudo python setup.py install. It seemed to install and then when I tried from bs4 import BeautifulSoup I got the error. – tforbes Sep 21 '16 at 22:05
  • @lxer I am quite sure that I'm not using a virtual environment, but I honestly wouldn't know. I simply downloaded Python, then downloaded PyCharm, then started trying to install these modules (not sure what they are called). Thank you. – tforbes Sep 21 '16 at 22:35
  • I would recommend going through the command line. GUIs and PyCharm may be nice, but `pip` is the recommended way to get packages installed. – OneCricketeer Sep 21 '16 at 22:45
  • @cricket_007 When you say command line, I assume you are referring to the terminal that is part of my Mac OSX right? Do I need to type python in front of the command, or simply pip install beautifulsoup – tforbes Sep 21 '16 at 22:59
  • @tforbes Yes, the "terminal" application, but commands are ran from the "command line" (they are synonymous). And no `python` unless you are running a script. `pip` is its own command. `install` is a sub-command, then `beautifulsoup` is the argument to install – OneCricketeer Sep 21 '16 at 23:02
  • @cricket_007 got it and thank you for that clarification. I tried easy_install beautifulsoup4 through the command line. I am not sure if it worked, but I didn't seem to get an error. – tforbes Sep 21 '16 at 23:04

1 Answers1

-2

You can use pip to install beautifulsoup on mac, by typing in the following command in Terminal:

pip install beautifulsoup4

You might be facing some permission problems if you are running the OS X preinstalled python as interpreter. I would suggest installing python with Homebrew if that's the case.

CasperTN
  • 441
  • 1
  • 5
  • 14
  • Thank you. When you say I might be facing permission problems, does the sudo command in front of what you typed help with that? – tforbes Sep 21 '16 at 22:45
  • @tforbes [Use a virtualenv](http://stackoverflow.com/a/15028735/2308683) – OneCricketeer Sep 21 '16 at 22:46
  • I typed the command as you had it and I received an error. I tried to copy and paste the error into a comment but it was too long. Is there a way for me to copy and paste code into these replies? – tforbes Sep 21 '16 at 22:51
  • 1
    Try: easy_install beautifulsoup4 – CasperTN Sep 21 '16 at 22:55
  • @CasperTN thank you, I typed that in using regular Mac terminal (not PyCharm). I don't know if it worked or not, but it said, Processing dependencies for beautifulsoup4 Finished processing dependencies for beautifulsoup4 . Is there a way for me to test if it worked? – tforbes Sep 21 '16 at 23:01
  • @cricket_007 Do I need to uninstall or delete what has already been done in order to setup a virtual environment? – tforbes Sep 21 '16 at 23:02
  • @tforbes You may need to install `virtualenv`, but no clean up is necessary. – OneCricketeer Sep 21 '16 at 23:04
  • 1
    The easiest way to check if its installed and in python path, open a terminal, run python and type from bs4 import BeautifulSoup if there is no error message then its installed and on python modules path – Ilhicas Sep 21 '16 at 23:04
  • @CasperTN I ran from bs4 import BeautifulSoup. I don't get any errors when I do it from terminal, I do get errors when I do it within PyCharm Python Console. Is that normal, and can I assume that the BeautifulSoup question has been successfully resolved? – tforbes Sep 21 '16 at 23:08
  • Try this: pip install bs4 – CasperTN Sep 21 '16 at 23:09
  • And then when you import: from bs4 import BeautifulSoup – CasperTN Sep 21 '16 at 23:09
  • Try to restart Pycharm to let it update its libraries – CasperTN Sep 21 '16 at 23:12
  • @CasperTN I received -- Successfully installed bs4-0.0.1. When I restart Pycharm, will it update it's libraries on its own, or is it something that I need to do specifically? – tforbes Sep 21 '16 at 23:18
  • Wow. Thank you all for your help. This seems to be working perfectly fine now. I am so very appreciative. How do I mark that this question was successfully resolved? – tforbes Sep 21 '16 at 23:21
  • First up vote it by clicking the up arrow and then click the green mark. – CasperTN Sep 21 '16 at 23:22