[英]django app on server: No module named 'django.urls'
I have a Django (v1.11.6)
app on my Ubuntu
server and was using Python v2.7
.我的Ubuntu
服务器上有一个Django (v1.11.6)
应用程序,并且使用的是Python v2.7
。
I am now using Python 3.5
(not using virtualenv
), however when I run sudo service apache2
restart I get the following error in my browser:我现在使用Python 3.5
(不使用virtualenv
),但是当我运行sudo service apache2
restart 时,我的浏览器出现以下错误:
ImportError at /
No module named 'django.urls'
Request Method: GET
Request URL: https://dev.ga.coach/
Django Version: 1.8.7
Exception Type: ImportError
Exception Value:
No module named 'django.urls'
Python Executable: /usr/bin/python3
Python Version: 3.5.2
When I run python3 manage.py runserver
I get no error.当我运行python3 manage.py runserver
我没有收到任何错误。
When I execute sudo pip freeze | grep -i 'django'
当我执行sudo pip freeze | grep -i 'django'
sudo pip freeze | grep -i 'django'
I get the following: sudo pip freeze | grep -i 'django'
我得到以下信息:
Django==1.11.6
django-allauth==0.33.0
django-filter==1.0.4
django-rest-auth==0.9.1
djangorestframework==3.6.3
djangorestframework-jwt==1.11.0
Your apache config is using Django 1.8.7 as you can see in your error.正如您在错误中看到的那样,您的 apache 配置正在使用 Django 1.8.7。 And you're using a newer method for including urls ( url(r'^users/', include('users.urls'), name='users')
inside urls.py
which wasn't supported in Django 1.8.并且您正在使用一种更新的方法在urls.py
中包含 url( url(r'^users/', include('users.urls'), name='users')
,Django 1.8 不支持该方法。
Since your switched from python 2.7 to python 3.5 it's quite likely your mod_wsgi
module is still the one compiled with python 2.7.由于您从 python 2.7 切换到 python 3.5,很可能您的mod_wsgi
模块仍然是使用 python 2.7 编译的模块。 Here's what the WSGI docs say about that:以下是WSGI 文档对此的描述:
When using a Python virtual environment with mod_wsgi, it is very important that it has been created using the same Python installation that mod_wsgi was originally compiled for.当使用带有 mod_wsgi 的 Python 虚拟环境时,使用与 mod_wsgi 最初编译时相同的 Python 安装来创建它是非常重要的。 It is not possible to use a Python virtual environment to force mod_wsgi to use a different Python version, or even a different Python installation.不可能使用 Python 虚拟环境来强制 mod_wsgi 使用不同的 Python 版本,甚至是不同的 Python 安装。
You cannot for example force mod_wsgi to use a Python virtual environment created using Python 3.5 when mod_wsgi was originally compiled for Python 2.7.例如,当 mod_wsgi 最初是为 Python 2.7 编译时,您不能强制 mod_wsgi 使用使用 Python 3.5 创建的 Python 虚拟环境。 This is because the Python library for the Python installation it was originally compiled against is linked directly into the mod_wsgi module.这是因为最初编译它的 Python 安装的 Python 库直接链接到 mod_wsgi 模块中。 In other words, Python is embedded within mod_wsgi.换句话说,Python 嵌入在 mod_wsgi 中。 When mod_wsgi is used it does not run the command line python program to run the interpreter and thus why you can't force it to use a different Python installation.当使用 mod_wsgi 时,它不会运行命令行 python 程序来运行解释器,因此你不能强制它使用不同的 Python 安装。
So try re-installing mod_wsgi
using python 3.5.所以尝试使用 python 3.5 重新安装mod_wsgi
。 That should then be able to find the Django package you installed with python 3.5.然后应该能够找到你用 python 3.5 安装的 Django 包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.