【发布时间】:2015-04-09 02:31:51
【问题描述】:
我正在使用以下设置在 EC2 上运行 django 应用程序
--home
-ubuntu
-AppFolder
--SomeInstalledApp
--SettingsDir
--settings.py
--wsgi.py
--templates
--static
-venv
我的 apache 服务器配置如下
WSGIScriptAlias / /home/ubuntu/AppFolder/SettingsDir/wsgi.py
WSGIPythonPath /home/ubuntu/venv/bin/python3.4
Alias /static/ /home/ubuntu/AppFolder/static/
Alias /admin_media/ /home/ubuntu/venv/bin/python3.4/site-packages/django/contrib/admin/media/
<Directory /home/ubuntu/AppFolder/SettingsDir>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
<Directory /home/ubuntu/AppFolder/static>
Require all granted
</Directory>
<Directory "/home/ubuntu/venv/bin/python3.4/site-packages/django/contrib/admin/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
在启动 Apache 服务器时,我可以访问 EC2 提供的公共 IP。但是,我收到以下错误:
ImportError at /
No module named request
我遇到了未找到模块的错误requests,但没有此类错误。如何解决此问题,以便让我的应用程序运行?
编辑
似乎错误源于使用import urllib.request,它在 python3 中可用,但在 python 2 中会引发错误。所以现在我需要弄清楚为什么我的 ec2 实例没有使用 Python3,即使它已安装。
【问题讨论】:
-
这个你试过了吗:superuser.com/a/568313
-
@Selcuk,是的,我确实安装了它。但它仍然给我同样的错误。可能是因为我在代码中使用了
import urllib.request而python 2.x 无法识别它吗?但是我已经将我的 WSGI python 路径设置为使用 3.4,所以我不确定这是否正确。 -
那你为什么将 Django 安装到 Python 2.7 dist-packages 中?
-
@Selcuk,是的,我意识到我的错误,我将其更改为安装在
venvvirtualenv 文件夹中。我已将/admin_media/Alias 指向正确的文件夹。 -
@Selcuk,我对问题进行了编辑
标签: python django amazon-web-services amazon-ec2