0

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.

Danielson
  • 88
  • 1
  • 8
  • what does `pip --version` output? – hansaplast Jan 20 '17 at 15:52
  • The output is, `pip 8.1.1 from C:\...\python35\lib\site-packages (python 3.5)` – Danielson Jan 20 '17 at 15:55
  • can you also add the output of `pip show bs4`? – hansaplast Jan 20 '17 at 15:58
  • The output suggested I upgrade from 8.1.1 to 9.0.1 with `python -m pip install --upgrade pip`. I upgraded to 9.0.1 and uninstalled bs4, then attempted to install again via the new version of pip. Still receiving the same error. – Danielson Jan 20 '17 at 16:10
  • this is really strange that you have a python2 version of bs4 installed in a python3 path (`Python35` is part of the path..) – hansaplast Jan 20 '17 at 16:14
  • Would it be best to uninstall everything Python related I can find on my pc, and reinstall? Could it be a remnant of Python 2 stopping me? – Danielson Jan 20 '17 at 16:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/133664/discussion-between-hansaplast-and-danielson). – hansaplast Jan 20 '17 at 17:36

1 Answers1

2

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
hansaplast
  • 11,007
  • 2
  • 61
  • 75