如何修复不同的python版本错误?

时间:2018-04-20 14:38:53

标签: python python-3.x python-2.7 flask mod-wsgi

我有3个不同的版本:

2.7, 3.5, 3.6

要安装Flask并运行Hello World,我一步一步地遵循本教程Flask 但是我将此命令ln -sf /usr/bin/python3 /usr/bin/python更改为:

ln -sf /usr/bin/python3.6 /usr/bin/python

现在它在日志中给我这个错误:

[Fri Apr 20 09:21:19.808894 2018] [mpm_event:notice] [pid 25752:tid 139701099587456] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Fri Apr 20 09:21:19.808980 2018] [core:notice] [pid 25752:tid 139701099587456] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:21:32.207980 2018] [mpm_event:notice] [pid 25752:tid 139701099587456] AH00491: caught SIGTERM, shutting down
[Fri Apr 20 09:21:33.319127 2018] [wsgi:warn] [pid 26013:tid 140126648674176] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Apr 20 09:21:33.319205 2018] [wsgi:warn] [pid 26013:tid 140126648674176] mod_wsgi: Runtime using Python/3.5.2.
[Fri Apr 20 09:21:33.320002 2018] [mpm_event:notice] [pid 26013:tid 140126648674176] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Apr 20 09:21:33.320024 2018] [core:notice] [pid 26013:tid 140126648674176] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:28:37.277698 2018] [mpm_event:notice] [pid 26013:tid 140126648674176] AH00491: caught SIGTERM, shutting down
[Fri Apr 20 09:28:38.336490 2018] [wsgi:warn] [pid 10166:tid 140069159778176] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Apr 20 09:28:38.336542 2018] [wsgi:warn] [pid 10166:tid 140069159778176] mod_wsgi: Runtime using Python/3.5.2.
[Fri Apr 20 09:28:38.337272 2018] [mpm_event:notice] [pid 10166:tid 140069159778176] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Apr 20 09:28:38.337294 2018] [core:notice] [pid 10166:tid 140069159778176] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:29:08.182299 2018] [mpm_event:notice] [pid 10166:tid 140069159778176] AH00491: caught SIGTERM, shutting down
[Fri Apr 20 09:29:09.224956 2018] [wsgi:warn] [pid 10290:tid 140446016731008] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Apr 20 09:29:09.225001 2018] [wsgi:warn] [pid 10290:tid 140446016731008] mod_wsgi: Runtime using Python/3.5.2.
[Fri Apr 20 09:29:09.225714 2018] [mpm_event:notice] [pid 10290:tid 140446016731008] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Apr 20 09:29:09.225740 2018] [core:notice] [pid 10290:tid 140446016731008] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:29:42.886467 2018] [wsgi:error] [pid 10294:tid 140445919373056] [client 134.193.130.121:56046] mod_wsgi (pid=10294): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python modul$
[Fri Apr 20 09:29:42.886529 2018] [wsgi:error] [pid 10294:tid 140445919373056] [client 134.193.130.121:56046] mod_wsgi (pid=10294): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.

我的理解是没有找到Flask模块。我又改变了版本,现在我迷失了。如何让"Hello World"工作?

1 个答案:

答案 0 :(得分:1)

这些日志不会显示实际错误以及您的应用无法加载的原因。您需要在包含的内容后查看消息。

可以忽略有关Python补丁级别的警告,如下所述:

如果要使用Python 3.6,则必须使用已为3.6编译的mod_wsgi安装。没有办法强制为3.5编译的mod_wsgi使用3.6。

您应该卸载mod_wsgi的系统包。然后根据Python 3.6自己编译mod_wsgi并使用它。最容易使用pip install方法:

然后运行mod_wsgi-express module-config以使配置包含在Apache配置中。如果只进行本地开发,请使用mod_wsgi-express start-server。请参阅该链接的文档。

您不能将pyenv与mod_wsgi一起使用,除非您采取额外步骤以确保pyenv为Python生成共享库,默认情况下不会这样做。