首页 > 解决方案 > 虽然裸 python 烧瓶成功启动,但我的 uwsgi 启动失败,出现奇怪的 python 库导入错误

问题描述

我用 uwsgi 托管的 python 烧瓶框架开发了一个网络服务器。它在一台计算机上运行良好,当我将它移植到另一台具有完全相同配置的计算机上时,即 Ubuntu 16.04、python 2.7、uwsgi 2.0,但 uwsgi 因奇怪的导入错误而失败。

我可以使用裸 python 命令行成功启动我的 Web 服务

python HelloCityEye.py

服务启动时一切正常。

    # python HelloCityEye.py
/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
2019-09-12 16:09:27,129 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2019-09-12 16:09:27,129 INFO sqlalchemy.engine.base.Engine ()
2019-09-12 16:09:27,130 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2019-09-12 16:09:27,130 INFO sqlalchemy.engine.base.Engine ()
2019-09-12 16:09:27,131 INFO sqlalchemy.engine.base.Engine PRAGMA main.table_info("users")
2019-09-12 16:09:27,131 INFO sqlalchemy.engine.base.Engine ()
 * Serving Flask app "HelloCityEye" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
2019-09-12 16:09:27,690 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2019-09-12 16:09:27,691 INFO sqlalchemy.engine.base.Engine ()
2019-09-12 16:09:27,691 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2019-09-12 16:09:27,691 INFO sqlalchemy.engine.base.Engine ()
2019-09-12 16:09:27,692 INFO sqlalchemy.engine.base.Engine PRAGMA main.table_info("users")
2019-09-12 16:09:27,692 INFO sqlalchemy.engine.base.Engine ()
 * Debugger is active!
 * Debugger PIN: 102-535-023

我可以使用任何网络浏览器访问我的网络服务。

然后我想用 uwsgi 框架托管烧瓶 Web 服务,如下配置为 temp.ini 文件(与以前的工作计算机相同)

[uwsgi]
chdir=/home/gongming/pythonwork/cityeye
virtualenv = /home/gongming/pythonwork/cityeye
module=HelloCityEye
callable=app

master=true
processes=20

http = 127.0.0.1:9090

但是,当我尝试使用以下命令启动 uwsgi

# ./bin/uwsgi temp.ini

错误消息跳转到 python 问题

(cityeye) root@ubuntu:/home/gongming/pythonwork/cityeye# ./bin/uwsgi temp.ini
[uWSGI] getting INI configuration from temp.ini
*** Starting uWSGI 2.0.12 (64bit) on [Thu Sep 12 16:44:06 2019] ***
compiled with version: 4.8.4 on 02 May 2016 17:58:33
os: Linux-4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/gongming/pythonwork/cityeye
detected binary path: /home/gongming/pythonwork/cityeye/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
setgid() to 33
setuid() to 33
chdir() to /home/gongming/pythonwork/cityeye
your processes number limit is 1903
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 127.0.0.1:9090 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:45929 (port auto-assigned) fd 3
Python version: 2.7.15rc1 (default, Nov 12 2018, 14:31:15)  [GCC 7.3.0]
Set PythonHome to /home/gongming/pythonwork/cityeye
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x11b0f90
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1527960 bytes (1492 KB) for 20 cores
*** Operational MODE: preforking ***
Traceback (most recent call last):
  File "./HelloCityEye.py", line 9, in <module>
    import Earth2Mars  # coordinate transformation
  File "./Earth2Mars.py", line 12, in <module>
    import numpy as np
  File "/home/gongming/pythonwork/cityeye/local/lib/python2.7/site-packages/numpy/__init__.py", line 201, in <module>
    from . import random
  File "/home/gongming/pythonwork/cityeye/local/lib/python2.7/site-packages/numpy/random/__init__.py", line 99, in <module>
    from .mtrand import *
ImportError: /home/gongming/pythonwork/cityeye/local/lib/python2.7/site-packages/numpy/random/mtrand.so: undefined symbol: PyFPE_jbuf
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 10716)
...
spawned uWSGI worker 20 (pid: 10737, cores: 1)
spawned uWSGI http 1 (pid: 10738)

即使我重新安装了 numpy 包,它也无济于事。

我确信它不应该是 python 库 ImportError,因为我不仅可以在没有托管 uwsgi 的情况下直接使用 python 运行它,而且我可以在另一台 ubuntu 计算机上使用 uwsgi 而没有任何问题。

那么,是什么导致了错误呢?

感谢关注。

标签: pythonflaskuwsgi

解决方案


推荐阅读