Installing BeautifulSoup4 via pip produces an impo

2019-09-14 09:47发布

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条回答
仙女界的扛把子
2楼-- · 2019-09-14 10:19

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
查看更多
登录 后发表回答