BUG之路2--ubuntu安装uwsgi测试报错:failed to open python file test.py

心路历程

毫无疑问,又是能让我跳楼的BUG,但是结果都一样,很小的细节,卡我两天时间。

BUG过程:

在ubuntu上部署django项目时,需要安装uwsgi服务器。根据教程安装完之后,然后会有一个小测试,就是写一个test.py文件运行一下看uwsgi是否安装成功。具体的test.py文件我就不贴了,网上一堆。
然后重要的是在运行命令:uwsgi –http :8001 –wsgi-file test.py时,报错了。详细错误信息如下:

dh@ubuntu:~$ uwsgi –http :8001 –wsgi-file test.py
Starting uWSGI 2.0.17 (64bit) on [Mon Jun 11 12:37:29 2018]
compiled with version: 7.3.0 on 07 June 2018 06:45:48
os: Linux-4.15.0-22-generic #24-Ubuntu SMP Wed May 16 12:15:17 UTC 2018
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/dh
detected binary path: /home/dh/.local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
WARNING: you are running uWSGI without its master process manager
your processes number limit is 15072
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 :8001 fd 4
spawned uWSGI http 1 (pid: 18207)
uwsgi socket 0 bound to TCP address 127.0.0.1:36073 (port auto-assigned) fd 3
Python version: 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0]
Python threads support is disabled. You can enable it with –enable-threads
Python main interpreter initialized at 0x55e5bf3e29c0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
Operational MODE: single process
failed to open python file test.py
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 worker 1 (and the only) (pid: 18206, cores: 1)

报错的就是最后那三句:

failed to open python file test.py
unable to load app 0 (mountpoint=”) (callable not found or import error)
no app loaded. going in full dynamic mode

报错原因:找不到test.py文件

解决方法:

在根据教程安装uwsgi时,我的理解是,安装完 ,直接在django项目里写一个test.py文件,再用命令运行就可以。
实际的步骤是:安装完uwsgi后,在任何位置都可以写这个test.py文件,然后打开终端运行命令时的位置必须和这个test.py文件位置相同,例如:test.py文件的路径是/home/etc/test.py,那你终端的位置也应该是/home/etc/test.py,就不会报这个错了。

最后再列一下安装uwsgi的正确步骤:

1.sudo apt-get install libpcre3 libpcre3-dev ,第一步必须先安装这个库文件,不然不报错:no internal routing support, rebuild with pcre support

2.sudo pip3 install uwsgi ,这里和上一篇注意的BUG一样,如果你是python3,就一定要用pip3安装

3.任何位置写一个test.py,内容如下
def application(env, start_response):
   start_response(‘200 OK‘, [(‘Content-Type‘,‘text/html‘)])
   return [b”Hello World”]

4.然后启动终端,和之前说的一样,终端的位置要和test的文件位置相同,运行命令:uwsgi –http :8001 –wsgi-file test.py

5.浏览器里输入:127.0.0.1:8001就可以看到输出效果:Hello World

OK了

你可能感兴趣的:(Python之路)