How to fix SyntaxError on autogenerated manage.py in Python

SyntaxError on autogenerated manage.py is an error which occurs when you forget to activate your virtual environment or when you use the wrong syntax when running manage.py.

In the blog post I attempt to explain why this error takes place and how you can solve it, I will also add other solutions that could solve the error if possible.

Exploring the Error : SyntaxError on autogenerated manage.py

This is an error which occurs when you forget to activate your virtual environment or when you use the wrong syntax when running manage.py.

The error message should look like the message bellow. Make sure you are not dealing with another error.

                                                                       #
SyntaxError: invalid syntax
                                                                       #

Bellow we will take care of the error using multiple possible solutions according to your needs.

Solution 1 : create a virtual env and activate it using source env/bin/activate

In most cases, the error occurs when you forget to activate your virtual env.

The first solution is to activate your virtual environment using the command bellow

                                                                       #
source env/bin/activate
# or source venv/Scripts/activate if you have Django 3
                                                                       #

If the above failed, then maybe you do not have a virtual env at all. You should start by creating one using the command bellow.

                                                                       #
virtualenv --python=python3 venv
                                                                       #

After the options above, the error should be gone. Try the methods bellow if that was not the case.

Solution 2 : use python3 manage.py instead of python manage.py

The second reason why the error occurs is because you are using the wrong syntax when running manage.py.

In most cases running the file using python3 fixes the problem.

                                                                       #
python3 manage.py <app-name>
# you should try this instead of ( python manage.py startapp <app-name> )
                                                                       #

Its worth to note that python3 fixes the problem only when you have used pip3 to install Django

The solutions above should be enough to solve the problem

Summing-up : 

This article is over guys, You can support us by donating to our Kofi account, you can find a red button at the top of this page. Good luck with your Python journey, keep coding, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/