Python Forum
Invalid Syntax error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Invalid Syntax error (/thread-21618.html)



Invalid Syntax error - mustfirst - Oct-07-2019

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



RE: Invalid Syntax error - buran - Oct-07-2019

how did you install bs4?


RE: Invalid Syntax error - mustfirst - Oct-07-2019

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)



RE: Invalid Syntax error - buran - Oct-07-2019

that is weird. try to uninstall it and install again
pip uninstall beautifulsoup4
and then
pip install beautifulsoup4


RE: Invalid Syntax error - buran - Oct-07-2019

by any chance do you have multiple python installations?


RE: Invalid Syntax error - mustfirst - Oct-07-2019

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.



RE: Invalid Syntax error - buran - Oct-07-2019

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?


RE: Invalid Syntax error - mustfirst - Oct-07-2019

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.


RE: Invalid Syntax error - buran - Oct-07-2019

(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


RE: Invalid Syntax error - deep_logic - Nov-11-2019

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