近期在努力把自己的项目从python2转到python3上,因为生产环境无法抛弃centos7,所以只好在centos7上安装了python3。装好了python3,将python命令软连接改成python3的,同时也将pip指向了python3版本的pip。一切都很顺利,但在用uwsgi启动一个django的web服务时才发现出了问题:服务是启动了,但是一访问接口就返回500,再一看uwsgi这边的日志,显示:no python application found 。

nginx+uwsgi+django的模式在之前多次配过,都没有出现问题啊,为啥一到了python3的环境下就出问题了?我的环境应该配置得差不多了啊,而且所有的模块也都是在python3的环境下装的啊。

再次检查了我的配置文件:

[uwsgi]
socket = 127.0.0.1:3031
chdir = /opt/testproj/
wsgi-file = testproj/wsgi.py
processes = 4
threads = 2

感觉也没有啥问题啊。于是又开始仔细查看uwsgi这边输出的日志,再往前看看,才看到了这么个报错:

*** Operational MODE: preforking+threaded ***
Traceback (most recent call last):
File "testproj/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***

没有找到django模块?原来成功启动只是一个假象,实际上现在uwsgi没找到django这个模块,一提供服务肯定就500了。

但是为啥会没有找到django模块呢?uwsgi和django都是用python3的pip来装的啊,虽然这个centos7上还有python2,但也只是为了让yum还能正常使用而保留的啊。

在网上一顿找,才发现,uwsgi还真是有点特殊,在python2和python3共存的系统上就会有点问题,这次启动时无法找到django模块是因为uwsgi命令使用python2的环境来进行了启动。需要在配置文件中指定所需要的库环境才可以。

于是开始找django的环境,使用pip show可以看到django安装的location:

[root@knktc testproj]# pip show django|grep -i location
Location: /usr/local/lib64/python3.6/site-packages

顺便把pytz的路径也找下:

[root@knktc testproj]# pip show pytz|grep -i location
Location: /usr/local/lib/python3.6/site-packages

把这两个路径使用pythonpath参数加入到配置文件中,修改后的uwsgi配置文件是下面的这个样子的:

[uwsgi]
socket = 127.0.0.1:3031
chdir = /opt/testproj/
wsgi-file = testproj/wsgi.py
processes = 4
threads = 2
pythonpath = /usr/local/lib64/python3.6/site-packages
pythonpath = /usr/local/lib/python3.6/site-packages

再启动一次试试:

uwsgi --ini uwsgi.ini

一切正常!

uwsgi no python application found错误的解决(python3+centos6)的更多相关文章

  1. Python: The _imagingft C module is not installed错误的解决

    Python: The _imagingft C module is not installed错误的解决 By 白熊花田(http://blog.csdn.net/whiterbear) 转载需注明 ...

  2. 关于Python打开IDLE出现错误的解决办法

    安装好python,打开IDLE出现以下错误: 解决办法: 修改[Python目录]\Lib\idlelib\PyShell.py文件,在1300行附近,将def main():函数下面use_sub ...

  3. 编程中遇到的Python错误和解决方法汇总整理

    这篇文章主要介绍了自己编程中遇到的Python错误和解决方法汇总整理,本文收集整理了较多的案例,需要的朋友可以参考下   开个贴,用于记录平时经常碰到的Python的错误同时对导致错误的原因进行分析, ...

  4. Python编程的10个经典错误及解决办法

    接触了很多Python爱好者,有初学者,亦有转行人.不论大家学习Python的目的是什么,总之,学习Python前期写出来的代码不报错就是极好的.下面,严小样儿为大家罗列出Python3十大经典错误及 ...

  5. 运行bee run之后出现的错误以及解决方法Failed to build the application:

      运行bee run之后出现的错误以及解决方法 创建一个beego项目 bee new myapp 在该项目执行下面的代码 bee run 出现的问题 2020/04/22 21:12:07 INF ...

  6. 解决:执行python脚本,提示错误:/usr/bin/python^M: 解释器错误: 没有那个文件或目录。

    执行python脚本,提示错误: /usr/bin/python^M: 解释器错误: 没有那个文件或目录. 产生错误原因: \r字符被显示为^M,这时候只需要删除这个字符就可以了. Linux环境下: ...

  7. Nginx+uWSGI+Django+Python+ MySQL 搭建可靠的Python Web服务器

    一.安装所需工具 yum -y install gcc gcc-c++ rpm-build mysql* libtool-ltdl* libtool automake autoconf libtool ...

  8. Invalid Binary错误怎么解决

      Invalid Binary错误怎么解决? 本文永久地址为http://www.cnblogs.com/ChenYilong/p/3989829.html ,转载请注明出处. iOS8升级过程中, ...

  9. Oracle的常见错误及解决办法

    ORA-12528: TNS:listener: all appropriate instances are blocking new connections ORA-12528问题是因为监听中的服务 ...

随机推荐

  1. Aliyun STS Java SDK示例

    package com.aliyun.oss.demo; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.exceptions.Cl ...

  2. [Algorithm] 617. Merge Two Binary Trees

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  3. Web协议详解与抓包实战:HTTP1协议-详解请求行(2)

    一.请求行一 二.请求行二 三.请求行三 四.常见方法(RFC7231) 实际测试截图 五.用于文档管理的 WEBDAV 方法(RFC2518) 六.WEBDAV 验证环境  1.登录  2.Wire ...

  4. [LeetCode] 719. Find K-th Smallest Pair Distance 找第K小的数对儿距离

    Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...

  5. 关于指针与引用的差别——C++

    准备 https://zhuanlan.zhihu.com/p/27974028 开始 int   是int类型变量声明 int * 是int指针声明,指针其实就是地址变量,用来储存地址值的" ...

  6. AtCoder Grand Contest 035 简要题解

    从这里开始 题目目录 Problem A XOR Circle 你发现,权值的循环节为 $a_0, a_1, a_0\oplus a_1$,然后暴力即可. Code #include <bits ...

  7. Mac上Hive安装配置

    Mac上Hive安装配置 1.安装 下载hive,地址:http://mirror.bit.edu.cn/apache/hive/ 之前我配置了集群,tjt01.tjt02.tjt03,这里hive安 ...

  8. laravel中如何执行请求

    laravel中如何执行request请求?本篇文章给大家介绍关于laravel中执行请求的方法,需要的朋友可以参考一下,希望对你有所帮助. 我们先来看一下request是什么? 客户端(例如Web浏 ...

  9. js对数组去重的方法总结-(2019-1)

    最近待业在家,系统地学习了一套js的课程.虽然工作时间真的比较长了,但有些东西只局限在知其然而不知其所以然的程度上,有些知识点通过“血和泪”的经验积累下来,也只是记了结果并没有深究,所以每次听完课都有 ...

  10. jax-rs 标准以及 结合 resteasy的使用

    jax-rs:https://baike.baidu.com/item/JAX-RS/10914743?fr=aladdin resteasy:https://www.iteye.com/blog/s ...