Can't import bs4 in python

108 views
Skip to first unread message

Rohit Mahale

unread,
Oct 3, 2019, 4:48:48 PM10/3/19
to beautifulsoup
I am trying to import the bs4 from python 3.7.4 by ' from bs4 import beautifulsoup4' but it is showing error as,

  File "<stdin>", line 1, in <module>
  File "C:\Python\lib\site-packages\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`).'

But, I have the latest version of beautifulsoup4 still, it is showing this error what shall I do.

Thanks.

Oliver Saunders

unread,
Oct 3, 2019, 5:01:08 PM10/3/19
to beauti...@googlegroups.com
Did you install using a download? Looks like yoube got the python2 version. If so try installing it using 'pip install beatifulsoup4' you may need to uninstall first

--
You received this message because you are subscribed to the Google Groups "beautifulsoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beautifulsou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beautifulsoup/3156d9c4-7de7-48aa-b299-4d20d846e522%40googlegroups.com.

Rohit Mahale

unread,
Oct 3, 2019, 5:04:34 PM10/3/19
to beautifulsoup
No actually I have python 3.7.4 as I have mentioned.

Malik Rumi

unread,
Oct 3, 2019, 6:02:39 PM10/3/19
to beauti...@googlegroups.com
Rohit:

You don't understand. Having Python 3 has nothing to do with what version of beautiful soup you have. You need the version of bs4 that works on Python 3. Please follow Oliver's suggestion.


“None of you has faith until he loves for his brother or his neighbor what he loves for himself.”


--
You received this message because you are subscribed to the Google Groups "beautifulsoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beautifulsou...@googlegroups.com.

facelessuser

unread,
Oct 3, 2019, 6:03:33 PM10/3/19
to beautifulsoup
The comment wasn't about your Python version, but the version of Beautiful Soup you installed.

The author currently has all the source as Python 2 code. When he releases it, he releases a Python 2 package, and converts the code to be compatible for Python 3 and releases that for Python 3.

So, if you download the source and try to install it on Python 3, it will not be compatible.

Daniel

unread,
Oct 5, 2019, 5:55:35 AM10/5/19
to beautifulsoup
I get Requirement Already Satisfied: beautifulsoup4 in my appdata/local/...python37 but still get modulenotfounderror before and after uninstall/reinstall.


On Thursday, October 3, 2019 at 3:02:39 PM UTC-7, Malik Rumi wrote:
Rohit:

You don't understand. Having Python 3 has nothing to do with what version of beautiful soup you have. You need the version of bs4 that works on Python 3. Please follow Oliver's suggestion.


“None of you has faith until he loves for his brother or his neighbor what he loves for himself.”


On Thu, Oct 3, 2019 at 4:04 PM Rohit Mahale <rohit...@aitglobalinc.com> wrote:
No actually I have python 3.7.4 as I have mentioned.



On Friday, October 4, 2019 at 2:18:48 AM UTC+5:30, Rohit Mahale wrote:
I am trying to import the bs4 from python 3.7.4 by ' from bs4 import beautifulsoup4' but it is showing error as,

  File "<stdin>", line 1, in <module>
  File "C:\Python\lib\site-packages\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`).'

But, I have the latest version of beautifulsoup4 still, it is showing this error what shall I do.

Thanks.

--
You received this message because you are subscribed to the Google Groups "beautifulsoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beauti...@googlegroups.com.

FMAPR .

unread,
Oct 5, 2019, 7:28:43 AM10/5/19
to beauti...@googlegroups.com
Before I started studying engineering I always heard that one of the engineer most powerful tools was to turn down a device and then turning it back up... (This is a metaphor ok?)

It seems that your problem is what everyone is saying, I just suggest that you uninstall bs4, find how to install a version of bs4 that is compatible with your python version for sure, and install it.

Regards,
Filipe Pinto Reis

To unsubscribe from this group and stop receiving emails from it, send an email to beautifulsou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beautifulsoup/c98cb955-b2cc-46c2-8ac7-c1ba78723072%40googlegroups.com.

Daniel

unread,
Oct 5, 2019, 12:35:47 PM10/5/19
to beautifulsoup
Ok i think it's fixed now. I knew something was up because I could run my python file in vscode by right clicking the file in the explorer and pressing run python file in terminal, but I couldn't actually run in by typing in the terminal. I had a 32 bit python and a 64 bit python in my Appdata/Local/Programs/Python and since Deleting the 32 bit version from there I can run my bs4 script from the terminal.
Reply all
Reply to author
Forward
0 new messages