欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决uWSGI 启动时ImportError: No module named

程序员文章站 2022-05-28 22:27:23
...
ImportError: No module named ipaddress
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: 2342)
spawned uWSGI worker 1 (pid: 2354, cores: 1)
spawned uWSGI worker 2 (pid: 2355, cores: 1)

今天在搭建服务运行环境的时候,发现了一个uwsgi报出的导入错误问题,如上看到的,实际上我的系统里已经安装了这个包,但是依然发生了导入错误,第一感觉就是环境变量的问题,所以一顿查涉及到环境变量的文件 .bashrc, .bash_profile, /etc/profile, 都看了,并没有发现什么问题,然后我又具体看一下uwsgi的启动日志,如下:

*** Starting uWSGI 2.0.15 (64bit) on [Fri Apr 26 17:33:55 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-16) on 08 April 2019 16:38:27
os: Linux-3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017
nodename: XQ
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 32
current working directory: /export/servers/app/mega
writing pidfile to /tmp/uwsgi.pid
detected binary path: /usr/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
chdir() to /export/servers/app/mega
your processes number limit is 32768
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 0.0.0.0:80 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:42021 (port auto-assigned) fd 3
Python version: 2.7.5 (default, Aug  4 2017, 00:39:18)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Python main interpreter initialized at 0x735fe0
python threads support enabled
your server socket listen backlog is limited to 200 connections
your mercy for graceful operations on workers is 60 seconds
mapped 710080 bytes (693 KB) for 6 cores
*** Operational MODE: preforking ***

发现uwsgi启动的时候用的是Python version: 2.7.5 ,我的系统是CentOS7.4,系统原来默认安装的是虚拟python2.7.5,而我在部署的时候,已经放弃2.7.5而使用2.7.9的版本,所以uwsgi使用的python环境一定不是我自己的环境,再看 detected binary path: /usr/bin/uwsgi ,这是使用uwsgi的路径,然后 我查了一下 uwsgi的位置

find / -name uwsgi
/usr/local/bin/uwsgi 
/usr/bin/uwsgi

发现有两个uwsgi,而uwsgi启动的时候是调用/usr/bin/uwsgi 下的uwsgi,不是我自己安装的 /usr/local/bin/uwsgi ,所以问题找到了,uwsgi的启动文件不正确,导致无法加载我已经安装的环境包,解决方法是删掉/usr/bin/uwsgi,建一个软连接

 ln -s /usr/local/bin/uwsgi /usr/bin/uwsgi

这样就解决问题了。总结一下,公司的CentOS7.4的系统模板(第一次使用),SA是做了自己的一些处理,而这些影响到我的项目启动,有坑没关系,慢慢踩就能踩过了

相关标签: uwsgi