通过pip安装BeautifulSoup4会为Python 3.5产生导入错误 [英] Installing BeautifulSoup4 via pip produces an import error for Python 3.5

查看:187
本文介绍了通过pip安装BeautifulSoup4会为Python 3.5产生导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Python 3.5安装beautifulsoup4,但是当我在Python 3.5.2 shell中调用"import bs4"进行测试时,却收到了以下错误消息:

I'm trying to install beautifulsoup4 for Python 3.5, however, I've made it to when I call 'import bs4' to test in the Python 3.5.2 shell, I receive the error below:

回溯(最近通话最近): 文件",第1行,在 导入bs4 文件"C:\ Users \ Dan \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ bs4__init __.py",第53行 您正在尝试在Python 3下运行Beautiful Soup的Python 2版本.这将不起作用.'<>'您需要通过安装(python setup.py install)或运行2to3()." ^ SyntaxError:语法无效

Traceback (most recent call last): File "", line 1, in import bs4 File "C:\Users\Dan\AppData\Local\Programs\Python\Python35\lib\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

我已按照以下路径运行pip以最初安装beatifulsoup4,我过去在公司代理服务器附近安装的命令是:$ pip install --proxy = proxy.com beautifulsoup4

I have followed the below path to run pip to originally install beatifulsoup4, the command I used to install around a company proxy was: $ pip install --proxy=proxy.com beautifulsoup4

C:\ Users \ Dan \ AppData \ Local \ Programs \ Python \ Python35 \ Scripts

C:\Users\Dan\AppData\Local\Programs\Python\Python35\Scripts

我以前在这台计算机上安装了Python 2.7,但是在安装3.5时我将其卸载了.如果我没有正确卸载Python 2.7,pip可能无法安装bs4并将其转换为3.5吗?我还尝试了Requests模块的这些相同步骤.我尝试使用Python Shell推荐的命令进行转换,但是我尝试使用"2to3"也失败了.感谢您的帮助.

I had a previous installation of Python 2.7 on this computer, however I uninstalled it when I installed 3.5. If I did not uninstall Python 2.7 properly, could pip have failed to install and convert bs4 for 3.5? I've also attempted these same steps with the Requests module. I have tried to convert using the commands recommended by the Python shell, but my attempts to use '2to3' have failed as well. Any help is appreciated.

推荐答案

以某种方式将bs4的python2版本安装到您​​的python3目录中.为了解决您需要手动修复的问题,请删除C:\Users\Dan\AppData\Local\Programs\Python\Python35\lib\中的所有bs4文件(bs4__init__.py文件以及bs4子目录)

Somehow a python2 version of of bs4 was installed into your python3 directory. In order to fix that you coult manually fix it by removing all bs4 files in C:\Users\Dan\AppData\Local\Programs\Python\Python35\lib\ (the bs4__init__.py file and also the bs4 subdirectory)

如果现在执行pip install bs4,则pip认为它已经安装了bs4,因此您需要执行以下操作:

If you now do a pip install bs4 then pip thinks it has bs4 already installed so you need to do this:

pip install bs4 --ignore-installed

这篇关于通过pip安装BeautifulSoup4会为Python 3.5产生导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆