tags:

views:

135

answers:

5

I downloaded beautifulsoup.py for use on a little project I'm making. Do I need to import this .py file in my project?

Do I just copy and paste the code somewhere inside my current python script?

Thank you for the help.

I found this but it doesn't say anything regarding Windows. http://mail.python.org/pipermail/tutor/2002-April/013953.html

I'm getting this error when using it. I copied and pasted the .py file to the folder where my project was on Windows Explorer, not this happens. Any suggestions? alt text

+7  A: 

If it's in the same directory as your little project, all you should need to do is:

import BeautifulSoup

If you are keeping it in some other directory, the easiest way to do it is:

from sys import path
path.append(path_to_Beautiful_Soup)

import BeautifulSoup

Python keeps track of where it is currently, and first looks in the current directory. Then it checks through all of the paths in sys.path for the module in question. If it cannot find it in any of those places, it throws an error.

Sean Vieira
+2  A: 

You have several choices:

  • you can cut and paste in the code, assuming the license permits etc. however, what happens when the code is updated?

  • you can put the code into the same directory (ie folder) as your code. Then all you need to do is say import beautifulsoup before you try to use it.

  • you can put the code somewhere in the python load path.

Charlie Martin
+1: Even though you forgot "You can read the tutorial and figure out it for yourself."
S.Lott
+3  A: 

When you install beautifulsoup the canonical way (with easy_install for example, or with a windows installer, if any) the beautifulsoup module will probably be added to your PYTHONDIR\lib\site-packages directory.

This means

import beautifulsoup

should do the trick.

Otherwise, adding beautifulsoup.py (if it's a single file) to your current project directory and then issuing import beautifulsoup should also do the trick.

ChristopheD
A: 

I've done it before, putting BeautifulSoup.py inside the same directory as the script and import it would work. If you have multiple scripts spread over different directories, put the beautifulsoup file in the root directory and do a relative import.

ultimatebuster
A: 

you have to install a new package correctly in python by using in the command line:

pip install BeautifulSoup 

if you don't know the name of the package use :

pip search beautiful 

and the pip will get all package that have "beautiful" in their name or description ...

One more thing that is very important ; and because you use eclipse (netbeans it's the same) and pydev as i can see; you should refresh the list of package used by pydev when installing a new package by going in the menu to (for eclipse) Window -> Preference -> Pydev -> Interpreter - Python and clicking on Apply why is that ?, so that you can use the full power of pydev correctly (code completion , F3 ...) and because Pydev don't know if a package has been added until you tell him so.

the steps are for eclipse you can do their analog in netbeans right ?

singularity