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)**

pip3 freeze我得到了这个:

> 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

所以我想将 encoding.py 中的代码更改为from django.utils.six import python_2_unicode_compatible from from from django.utils.encoding import python_2_unicode_compatiblefile,因为我正在使用 python3.7 。我在站点包下找不到 django 目录。那么该怎么办 ?

4

2 回答 2

0

您使用 pip 安装了 djano,在您的系统中,它用于安装 python2 的软件包。所以,这就是django安装的,使用python2的django包。但是您使用 python3 运行它,因此出现错误。

你需要做的是通过pip3 install django.

通过运行确保您的虚拟环境也使用 python3 python -v。如果 python 实际指向 python2 安装,请检查该命令是否python3存在。如果是这样,请使用它。

于 2020-04-10T13:42:17.370 回答
0
  1. 为 django 设置虚拟环境
  2. 将所有需要的包放入 requirements.txt
  3. pip3 install -r requirements.txt
  4. docker-compose 构建
  5. 码头工人组成 -d

完毕

于 2021-03-26T06:35:43.697 回答