我想创建自己的API,所以我选择了apache2,uwsgi,flask和python。 我遵循了这些说明here
我更改了模块:
我更改了命令:
至此,我可以正常继续该指南,并使系统正常运行。 但是当我尝试添加自己的文件时,出现了错误
配置了Apache / 2.4.18(Ubuntu)mod_wsgi / 4.3.0 Python / 3.5.2
Apache error.log:
[Wed Jun 27 15:12:53.838360 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] mod_wsgi (pid=24654): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
[Wed Jun 27 15:12:53.838397 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] mod_wsgi (pid=24654): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Wed Jun 27 15:12:53.838553 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] Traceback (most recent call last):
[Wed Jun 27 15:12:53.838572 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] File "/var/www/FlaskApp/flaskapp.wsgi", line 11, in <module>
[Wed Jun 27 15:12:53.838574 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] from FlaskApp import app as application
[Wed Jun 27 15:12:53.838577 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 3, in <module>
[Wed Jun 27 15:12:53.838579 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] import utils
[Wed Jun 27 15:12:53.838587 2018] [wsgi:error] [pid 24654:tid 140042661635840] [remote 192.168.1.6:38961] ImportError: No module named 'utils'
这是apache conf文件:
<VirtualHost *:80>
ProxyPreserveHost On
ServerAdmin webmaster@localhost
WSGIScriptAlias /api /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
ProxyPass /api !
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ErrorDocument 404 /index.html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
系统运行时,我确实检查了__init __:py文件在哪里看到了自己的声音
路径:/ var / www / FlaskApp / FlaskApp
在python或虚拟环境中的apache之外运行时,所有这些都有效
我还尝试通过pip安装模块,但它们不起作用
答案 0 :(得分:0)
尝试在wsgi文件中的导入之前添加以下行:
import sys
sys.path.append("/path/to/directory/containing/utils")