Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid Syntax error
#1
When I run the following I'm getting an error message. Anyone knows how to correct it?


>>> import requests
>>> from bs4 import BeautifulSoup
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\mustf\AppData\Local\Programs\Python\Python37\bs4\__init__.py", line 52 '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
Reply
#2
how did you install bs4?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I'm on Windows10. I used the following:

C:\Users\mustf\AppData\Local\Programs\Python\Python37\Scripts>pip install beautifulsoup4
Requirement already satisfied: beautifulsoup4 in c:\users\mustf\appdata\local\programs\python\python37 (4.8.0)
Requirement already satisfied: soupsieve>=1.2 in c:\users\mustf\appdata\local\programs\python\python37\lib\site-packages\soupsieve-1.9.4-py3.7.egg (from beautifulsoup4) (1.9.4)
Reply
#4
that is weird. try to uninstall it and install again
pip uninstall beautifulsoup4
and then
pip install beautifulsoup4
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
by any chance do you have multiple python installations?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
Cannot be uninstalled. I tried the these :'(

Error:
C:\Users\mustf\AppData\Local\Programs\Python\Python37\Scripts>pip uninstall beautifulsoup4 Can't uninstall 'beautifulsoup4'. No files were found to uninstall.
Error:
C:\Users\mustf\AppData\Local\Programs\Python\Python37\Scripts>pip uninstall BeautifulSoup WARNING: Skipping BeautifulSoup as it is not installed.
Reply
#7
I guess you did something you don't tell us. i.e. if it was install via pip install beautifulsoup4 as you claim, e.g. did you move something between folders?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
I moved the content of C:\temp\beautifulsoup4-4.8.0
to C:\Users\mustf\AppData\Local\Programs\Python\Python37\Scripts
then install BS using PIP.

I fixed the issue. I uninstalled Python and removed the folders and reinstalled everything from scratch.
Reply
#9
(Oct-07-2019, 06:32 PM)mustfirst Wrote: I moved the content of C:\temp\beautifulsoup4-4.8.0
that was the problem. don't do such things. always follow instructions on how to install (in most cases just pip install <package>) would do)

(Oct-07-2019, 06:32 PM)mustfirst Wrote: then install BS using PIP.
in fact you didn't install anything
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
Hi all,
It seems like I have the same problem as @mustf. I have python3.7 installed and have my windows environment variable set up to run from a cmd prompt. I have MSVS 2019 installed that seems to have some of the beautifulsoup4 modules. I have pycharm installed as well.
When I run pip from the cmd line and install bs4, it is listed as installed.
But, when I open idle, I list the modules, it's not listed their.
Maybe, I should uninstall pycharm or MSVS 2019?
I'm on windows10.
Thanks for any help
"Human history becomes more and more a race between education and catastrophe." - H. G. Wells (1866-1946)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,012 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 334 Jan-19-2024, 01:20 PM
Last Post: rob101
  error: invalid command 'egg_info' TimTu 0 908 Jul-27-2023, 07:30 AM
Last Post: TimTu
  Syntax error while executing the Python code in Linux DivAsh 8 1,451 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,136 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  print(data) is suddenly invalid syntax db042190 6 1,120 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  syntax error question - string mgallotti 5 1,251 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 10,654 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020