Installing BeautifulSoup4 via pip produces an import error for Python 3.5

China☆狼群 提交于 2019-12-12 01:24:24

问题


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:

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

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

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.


回答1:


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)

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


来源:https://stackoverflow.com/questions/41767507/installing-beautifulsoup4-via-pip-produces-an-import-error-for-python-3-5

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