Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BeautifulSoup4 can't be installed in python3.5 on Windows7

I have downloaded beautifulsoup4-4.5.3.tar.gz from https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/ and unzipped it to my python work directory(which is not my python install directory).

However, when I run

from bs4 import BeautifulSoup

in my IDLE the error massage popped out:

>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from bs4 import BeautifulSoup
File "D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\bs4\__init__.py", 
line 53
'You are trying to run the Python 2 version of Beautiful Soup under Python 
3. This will not work.'<>'You need to convert the code, either by installing 
it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).'

 ^
SyntaxError: invalid syntax

I tried these methods but the error massage above keeps popping out

  1. open setup.py in my IDLE and run it(gives === RESTART: D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\setup.py === in IDLE windows, but from bs4 import BeautifulSoup didn't work)
  2. use cmd and go to D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3, run pip uninstall beautifulsoup4 then run pip install beautifulsoup4;it shows that I have successfully installed beautifulsoup4-4.5.3 in cmd line, however, error massage still appearred in IDLE after from bs4 import BeautifulSoup
  3. use cmd and go to D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3, run pip3 uninstall beautifulsoup4 then run pip3 install beautifulsoup4; useless as above
  4. run pip install bs4 --ignore-installed,useless as above
  5. run setup.py install,useless as above
  6. run 2to3 -w bs4 in cmd line under D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3, returns '2to3' is not recognized as an internal or external command,operable program or batch file.

what should I do?

beside,pip show bs4 gives this

`Metadata-Version: 1.1
Name: bs4
Version: 0.0.1
Summary: Screen-scraping library
Home-page: https://pypi.python.org/pypi/beautifulsoup4
Author: Leonard Richardson
Author-email: [email protected]
License: MIT
Location: c:\users\myname\appdata\local\programs\python\python35-
32\lib\site-packages
Requires: beautifulsoup4
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' 
command.`

under my C:\Users\myname\AppData\Local\Programs\Python\Python35-32\Lib\site-packages directory, I can see three beautifulsoup related directories:beautifulsoup4-4.5.3.dist-info, bs4 and bs4-0.0.1-py3.5.egg-info, but from bs4 import BeautifulSoup keep throwing out wrong message

like image 796
Harry Avatar asked Oct 17 '22 13:10

Harry


1 Answers

BeautifulSoup4 is compatible with Python 3x and 2x, but the installation process is a bit different. The following is how I installed it for Python 3x.

Go to http://www.crummy.com/software/BeautifulSoup/#Download or https://pypi.python.org/pypi/beautifulsoup4/4.3.2 and download beautifulsoup4-4.3.2.tar.gz.

Navigate to the folder where you downloaded the file. Use 7zip to extract the beautifulsoup4-4.3.2.tar.gz file.

Double click the beautifulsoup4-4.3.2.tar.gz folder to drill down though the dist folder and then extract the beautifulsoup4-4.3.2.tar file.

Double click the beautifulsoup4-4.3.2.tar folder to drill down through yet another beautifulsoup4-4.3.2 folder. Inside the beautifulsoup4-4.3.2 folder you will see the setup.py file.

Hold down the Shift key while right clicking anywhere inside the folder and select Open command window here.

At the command prompt type: setup.py install and press Enter.

When then installation stops running, verify that the package was installed by navigating to the C:\Python34\Lib\site-packages directory. If installed you will see the bs4 directory.

Verify that the installation is working by going to Go to Start > All Programs > Python 3.4 > IDLE (Python 3.4 GUI 32 bit) to launch the basic IDE.

After the prompt type: >>>from bs4 import BeautifulSoup

If you receive no errors it is working.

like image 121
bigbounty Avatar answered Oct 20 '22 23:10

bigbounty