![](/img/trans.png)
[英]Can't import python modules or my own modules when I try to run apache
[英]Can't import my own .py modules in python when run from apache uwsgi
我想創建自己的API,因此選擇了apache2,uwsgi,flask和python。 我在這里遵循了這些指示
我更改了模塊:
我更改了命令:
至此,我可以正常繼續該指南,並使系統正常運行。 但是當我嘗試添加自己的文件時,出現了錯誤
已配置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安裝模塊,但它們不起作用
嘗試在wsgi文件中的導入之前添加以下行:
import sys
sys.path.append("/path/to/directory/containing/utils")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.