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

六眼飞鱼酱① 提交于 2019-11-29 22:59:22

问题


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: leonardr@segfault.org
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


回答1:


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.




回答2:


This problem solved in three steps:

First, delete all the beautifulsoup related directories and files under your python install directory, I mean all the beautifulsoup related directories under this C:\Users\yourname\AppData\Local\Programs\Python\Python35-32\Lib\site-packages

second, run pip uninstall beautifulsoup4 then pip install beautifulsoup4 under D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3 in cmd line, that is, where setup.py lies.

third, you need open setup.py in your IDLE and Run Module

finally, run from bs4 import BeautifulSoup in main IDLE windows. No error message now.



来源:https://stackoverflow.com/questions/43802910/beautifulsoup4-cant-be-installed-in-python3-5-on-windows7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!