0

I am working on a bug project. Which is on Python 2.7, we are migrating to Python 3.9. I am getting import errors in manage.py during importfrom django.core.management import execute_from_command_line. For python 2.7 it is fine but for python 3 it is not working. I've created separate virtual environment for Python 3.

manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "best_buy_mall.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

dir tree: my_app/django_site/manage.py

my_app/venv (for python2)

my_app/v_env (for python3)

1
  • Can you please provide the exception description? Have you installed django on the new environment? Can you please check and send pip list from the new python3 env? Commented Dec 30, 2021 at 20:30

2 Answers 2

1
sudo pip install django --upgrade 

I solved this by upgrading django. and if someone getting psycopg2 error, then run

sudo pip install psycopg2 --upgrade 

or install psycopg-binary

sudo pip install psycopg2-binary --upgrade 
Sign up to request clarification or add additional context in comments.

Comments

0

This code works

    sudo apt-get update

1 Comment

Avoid code only answer and provide an explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.