0
**Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.7/site-packages/rest_framework/authtoken/models.py", line 6, in <module>
    from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/usr/local/lib/python3.7/site-packages/django/utils/encoding.py)**

with pip3 freeze i got this :

> apturl==0.5.2 asgiref==3.2.7 asn1crypto==0.24.0 attrs==19.3.0
> bcrypt==3.1.7 Brlapi==0.6.6 cached-property==1.5.1 certifi==2019.11.28
> cffi==1.14.0 chardet==3.0.4 command-not-found==0.3 cryptography==2.9
> cupshelpers==1.0 cycler==0.10.0 defer==1.0.6
> distro-info===0.18ubuntu0.18.04.1 Django==3.0.5
> djangorestframework==3.9.4 docker==4.2.0 docker-compose==1.25.4
> dockerpty==0.4.1 docopt==0.6.2 entrypoints==0.3 flake8==3.7.0
> httplib2==0.9.2 idna==2.9 importlib-metadata==1.6.0 jsonschema==3.2.0
> keyring==10.6.0 keyrings.alt==3.0 kiwisolver==1.1.0
> language-selector==0.1 launchpadlib==1.10.6 lazr.restfulclient==0.13.5
> lazr.uri==1.0.3 louis==3.5.0 macaroonbakery==1.1.3 Mako==1.0.7
> MarkupSafe==1.0 matplotlib==3.2.1 mccabe==0.6.1 mysqlclient==1.4.6
> netifaces==0.10.4 numpy==1.18.2 oauth==1.0.1 olefile==0.45.1
> paramiko==2.7.1 pexpect==4.2.1 Pillow==5.1.0 protobuf==3.0.0
> psycopg2==2.7.7 pycairo==1.16.2 pycodestyle==2.5.0 pycparser==2.20
> pycrypto==2.6.1 pycups==1.9.73 pyflakes==2.1.1 pygobject==3.26.1
> pymacaroons==0.13.0 PyNaCl==1.3.0 pyparsing==2.4.6 pyRFC3339==1.0
> pyrsistent==0.16.0 python-apt==1.6.5+ubuntu0.2 python-dateutil==2.8.1
> python-debian==0.1.32 pytz==2019.3 pyxdg==0.25 PyYAML==5.3.1
> queuelib==1.5.0 reportlab==3.4.0 requests==2.23.0
> requests-unixsocket==0.1.5 SecretStorage==2.3.1 simplejson==3.13.2
> six==1.14.0 sqlparse==0.3.1 system-service==0.3 systemd-python==234
> texttable==1.6.2 ubuntu-drivers-common==0.0.0 ufw==0.36
> unattended-upgrades==0.1 urllib3==1.25.8 usb-creator==0.3.3
> virtualenv==15.1.0 wadllib==1.3.2 websocket-client==0.57.0 xkit==0.0.0
> zipp==3.1.0 zope.interface==4.3.2

so i want to change the code in encoding.py to from django.utils.six import python_2_unicode_compatible from from django.utils.encoding import python_2_unicode_compatiblefile as i am using python3.7 . i cant find the django directory under the site-packages. so what to do ?

  • Are you working in a virtual environment? If yes, what is the python version of your virtual environment and how did you install django? – Sanil Khurana Apr 10 '20 at 12:09
  • I am using docker container, and i am running python3.6.9 .and installed django using pip install command – Aditya Prasad Apr 10 '20 at 13:15
  • Run ```pip -V``` in your docker container. In the output you will get which version of python is being used. Also, see if there is a ```pip3``` command. – Sanil Khurana Apr 10 '20 at 13:18
  • i ran pip -V and its showing pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7) and yes pip3 is available – Aditya Prasad Apr 10 '20 at 13:30

1 Answers1

0

You installed djano with pip which, in your system, is for installing packages for python2. So, that's what django installed, the django package that uses python2. But you are running it with python3, hence the error.

What you need to do is to install django for python3 by pip3 install django.

Ensure your virtual environment is also using python3 by running python -v. If python is actually pointing to a python2 installation, check if the command python3 exists. If it does, use that.

Sanil Khurana
  • 1,129
  • 9
  • 20
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/211378/discussion-on-answer-by-sanil-khurana-no-django-file-in-the-site-packages). – Samuel Liew Apr 10 '20 at 15:39