Problems importing libraries in Python

3

I'm doing a tutorial on beautifulsoup in Python (version 2.7) with the following code:

from bs4 import BeautifulSoup
import urllib2

f = open ('C:\Python27\project\FFootball_DiamondMine\outfileESPN.txt','w')
errorFile = open ('C:\Python27\project\FFootball_DiamondMine\errorESPN.txt','w')

x = 0
while (x < 500):
    soup = BeautifulSoup(urllib2.urlopen('http://games.espn.com/ffl/tools/projections?startIndex='+str(x)).read(), 'html')
    tableStats = soup.find("table", {"class": "playerTableTable tableBody"})
    for row in tableStats.findAll('tr')[2:]:
        col =row.findAll('td')

        try:
            name = col[0].a.string.strip()
            f.write(name+'\n')

        except Exception as e:
            errorFile.write(str(x) + '*********' + str(e) + '**********' + str(col) +'\n')
            pass

    x = x + 40

f.close()
errorFile.close()

and when I try to run it on the console I get the following error

C:\Users\Vaio\PycharmProjects\tutorial>py demo.py
Traceback (most recent call last):
  File "demo.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named 'bs4'

It has been happening to me with other libraries but I do not understand what I'm doing wrong

sistema operativo : windows 7
Python: 2.7
BeautifulSoup: 3.2.1

Thank you very much for your response and attention

    
asked by Tajaludo 16.03.2017 в 02:20
source

1 answer

3

Just that, you can see that the version you have in BeautifulSoup, is in 3.2.1.

Try installing:

$ pip install BeautifulSoup4

If you are in python3 and you have version 2 already installed, you will have

$ pip3 install BeautifulSoup4

Try it and tell us your result (:

    
answered by 16.03.2017 / 02:51
source