无法在Windows7的python3.5中安装BeautifulSoup4 [英] BeautifulSoup4 can't be installed in python3.5 on Windows7
问题描述
我已经从 https://www.crummy.com/下载了beautifulsoup4-4.5.3.tar.gz ://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/并将其解压缩到我的python工作目录(不是我的python安装目录).>
但是,当我跑步
from bs4 import BeautifulSoup
在我的IDLE中弹出错误消息:
>>> 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
我尝试了这些方法,但是上面的错误提示一直弹出
- 在我的IDLE中打开setup.py并运行它(在IDLE窗口中提供
=== RESTART: D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3\setup.py ===
,但from bs4 import BeautifulSoup
无效) - 使用cmd转到D:\ python \ beautifulsoup4-4.5.3 \ beautifulsoup4-4.5.3,运行
pip uninstall beautifulsoup4
然后运行pip install beautifulsoup4
;这表明我已经在cmd行中成功安装了beautifulsoup4-4.5.3但是,from bs4 import BeautifulSoup
之后,IDLE中仍然出现错误消息
- 使用cmd转到
D:\ python \ beautifulsoup4-4.5.3 \ beautifulsoup4-4.5.3,先运行
pip3 uninstall beautifulsoup4
然后运行pip3 install beautifulsoup4
; 如上所述没用 - 运行
pip install bs4 --ignore-installed
,如上所述无效 - 运行
setup.py install
,如上所述无效 - 在cmd行中在D:\ python \ beautifulsoup4-4.5.3 \ beautifulsoup4-4.5.3下运行
2to3 -w bs4
,返回'2to3' is not recognized as an internal or external command,operable program or batch file.
我该怎么办?
在旁边,pip show bs4
给出了这个
`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.`
在我的C:\ Users \ myname \ AppData \ Local \ Programs \ Python \ Python35-32 \ Lib \ site-packages目录下,我可以看到三个与beautifulsoup相关的目录:beautifulsoup4-4.5.3.dist-info,bs4和bs4-0.0.1-py3.5.egg-info,但from bs4 import BeautifulSoup
总是抛出错误消息
BeautifulSoup4与Python 3x和2x兼容,但安装过程略有不同.以下是我为Python 3x安装它的方式.
转到 http://www.crummy.com/software/BeautifulSoup/#Download 或 https://pypi.python.org/pypi/beautifulsoup4/4.3 .2 并下载beautifulsoup4-4.3.2.tar.gz.
导航到下载文件的文件夹.使用7zip解压缩beautifulsoup4-4.3.2.tar.gz文件.
双击beautifulsoup4-4.3.2.tar.gz文件夹以深入dist文件夹,然后解压缩beautifulsoup4-4.3.2.tar文件.
双击beautifulsoup4-4.3.2.tar文件夹可深入浏览另一个beautifulsoup4-4.3.2文件夹.在beautifulsoup4-4.3.2文件夹中,您会看到setup.py文件.
按住Shift键的同时右键单击文件夹内的任意位置,然后在此处选择打开命令窗口".
在命令提示符下,键入:setup.py install并按Enter.
然后,当安装停止运行时,请导航至C:\ Python34 \ Lib \ site-packages目录,以验证该软件包已安装.如果已安装,您将看到bs4目录.
通过转到开始">所有程序">"Python 3.4">"IDLE"(Python 3.4 GUI 32位)以启动基本IDE,以验证安装是否正常.
在提示符后键入:>>>从bs4导入BeautifulSoup
如果您没有收到任何错误,则说明它正常工作.
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
- 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, butfrom bs4 import BeautifulSoup
didn't work) - use cmd and go to D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3, run
pip uninstall beautifulsoup4
then runpip install beautifulsoup4
;it shows that I have successfully installed beautifulsoup4-4.5.3 in cmd line, however, error massage still appearred in IDLE afterfrom bs4 import BeautifulSoup
- use cmd and go to
D:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3, run
pip3 uninstall beautifulsoup4
then runpip3 install beautifulsoup4
; useless as above - run
pip install bs4 --ignore-installed
,useless as above - run
setup.py install
,useless as above - 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
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.
这篇关于无法在Windows7的python3.5中安装BeautifulSoup4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!