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了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章