但是,当我跑步from bs4 import BeautifulSoup在我的IDLE中弹出错误消息:>>> from bs4 import BeautifulSoupTraceback (most recent call last):File "<pyshell#6>", line 1, in <module>from bs4 import BeautifulSoupFile "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 Python3. This will not work.'<>'You need to convert the code, either by installingit (`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,先运行pip3uninstall 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.1Name: bs4Version: 0.0.1Summary: Screen-scraping libraryHome-page: https://pypi.python.org/pypi/beautifulsoup4Author: Leonard RichardsonAuthor-email: [email protected]: MITLocation: c:\users\myname\appdata\local\programs\python\python35-32\lib\site-packagesRequires: beautifulsoup4You 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 BeautifulSoupin my IDLE the error massage popped out:>>> from bs4 import BeautifulSoupTraceback (most recent call last):File "<pyshell#6>", line 1, in <module>from bs4 import BeautifulSoupFile "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 Python3. This will not work.'<>'You need to convert the code, either by installingit (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).' ^SyntaxError: invalid syntaxI tried these methods but the error massage above keeps popping outopen 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)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 BeautifulSoupuse cmd and go toD:\python\beautifulsoup4-4.5.3\beautifulsoup4-4.5.3, run pip3uninstall beautifulsoup4 then run pip3 install beautifulsoup4;useless as aboverun pip install bs4 --ignore-installed,useless as aboverun setup.py install,useless as aboverun 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.1Name: bs4Version: 0.0.1Summary: Screen-scraping libraryHome-page: https://pypi.python.org/pypi/beautifulsoup4Author: Leonard RichardsonAuthor-email: [email protected]: MITLocation: c:\users\myname\appdata\local\programs\python\python35-32\lib\site-packagesRequires: beautifulsoup4You 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 BeautifulSoupIf you receive no errors it is working. 这篇关于无法在Windows7的python3.5中安装BeautifulSoup4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-14 12:09