[Tutor] trouble with beautiful soup
Walter Prins
wprins at gmail.com
Thu Dec 24 17:16:55 EST 2015
Hi,
On 24 December 2015 at 17:21, marcus lütolf <marcus.luetolf at bluewin.ch>
wrote:
> I am getting the following trace back without beeing prompted for an input:
>
> Traceback (most recent call last):
> File "C:/Python27/Beautiful Soup_ex1.py", line 2, in <module>
> from beautifulspoup import *
> ImportError: No module named beautifulspoup
>
> I have installed and unzipped etc. the latest file from www.crummy.com
> many times.
> If I click setup.py the command window appears only a fraction of a second.
> ??????
>
Slow down right there. It sounds like you're manually downloading the
module and then trying to install it by double clicking setup.py. Am I
right? If so, don't do that. (Perhaps.) Manually downloading and
installing modules is arguably not the easiest/preferred way.
I'll explain an alternate/easier way below. But if you must and because
it's arguably also good to know how to do this a bit more manually, open a
command prompt, then enter the following commands:
cd <extraction folder>
python setup.py install
Obviously you need to substitute where you extract the module sources into
the above cd command.
Then pay careful attention to any error messages output when the setup
script runs and post these if the installation is not successful.
I'll further note that it's much easier to install python packages with the
package manager "pip". To make this work you need to however get pip
itself installed first. To do this, download the instructions on the
following page: https://pip.pypa.io/en/stable/installing/ (basically
download and run the get-pip.py script.)
Once it's installed you can install modules by simply typing:
pip install <pacakge>
In your case this would simply be:
pip install beautifulsoup
At which you should get output something like the following:
C:\Python27\Scripts>pip install beautifulsoup
You are using pip version 7.0.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting beautifulsoup
Downloading BeautifulSoup-3.2.1.tar.gz
Installing collected packages: beautifulsoup
Running setup.py install for beautifulsoup
Successfully installed beautifulsoup-3.2.1
C:\Python27\Scripts>
You can issue the pip command from any folder, providing your
"C:\Python27\Scripts" folder is on your system path. While it might be by
default, I don't want to assume it, and if you have multiple versions of
Python then you need to careful to not make assumptions about which Python
and which pip is being run and should check or be explicit.
After installing a module the easiest way to sanity check the module is in
fact installed, is to immediately run the Python interpreter and try to
import the module:
C:\Python27\Scripts>cd ..
C:\Python27>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import BeautifulSoup
>>> dir(BeautifulSoup)
['BeautifulSOAP', 'BeautifulSoup', 'BeautifulStoneSoup', 'CData',
'Comment', 'DEFAULT_OUTPUT_ENCODING', 'Declaration',
'ICantBelieveItsBeautifulSoup', 'MinimalSoup', 'NavigableString',
'PageElement', 'ProcessingInstruction', 'ResultSet', 'RobustHTMLParser',
'RobustInsanelyWackAssHTMLParser', 'RobustWackAssHTMLParser',
'RobustXMLParser', 'SGMLParseError', 'SGMLParser', 'SimplifyingSOAPParser',
'SoupStrainer', 'StopParsing', 'Tag', 'UnicodeDammit', '__author__',
'__builtins__', '__copyright__', '__doc__', '__file__', '__license__',
'__name__', '__package__', '__version__', '_match_css_class',
'buildTagMap', 'chardet', 'codecs', 'generators', 'markupbase',
'name2codepoint', 're', 'sgmllib', 'types']
>>> print BeautifulSoup.__version__
3.2.1
Note that the Python package name is case sensitive, and that the 3.2.1
version package name is BeautifulSoup whilst the 4.x package name is bs4.
Obviously this may also explain why you're having problems.
Merry Christmas,
Walter
More information about the Tutor
mailing list