Centos 6.9 下安裝Python3.6.3+ uWSGI

1、廢話

之前利用Django寫了些測試工具,一直是直接 python manage.py runserver 8081這麼來用的。用戶量不大,倒也不影響什麼。uWSGI+Nginx的性能肯定要好,so 研究了一下

2、環境:

Python: 3.6.3

Django: 1.8

OS: CentOS 6.9 x86_64

uwsgi: 2.0.17

3、安裝Python3.6

  • 不要刪除自帶的python2.7,否則會出問題,因爲centos許多軟件需要依賴系統自帶python
  • 安裝依賴工具 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
  • 下載 wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
  • 解壓 tar -zxvf Python-3.6.3.tgz
  • 移動至規範的放軟件的目錄下 mv Python-3.6.3 /usr/local
  • 安裝:
  • cd /usr/local/Python-3.6.3/
  • ./configure
  • make&&make install
    解決Python.h No such file or directory
     
    
    1.可以先查看一下含python-devel的包
    
        yum search python | grep python-devel
    
    2.64位安裝python-devel.x86_64,32位安裝python-devel.i686,我這裏安裝:
    
        sudo yum install python-devel.x86_64
    
    3. 進入/usr/include/python2.7看一下現在有沒有Python.h,版本不同目錄名不同,我這裏是2.7版本。其實也可以看到很多.h文件,python需要庫或頭文件都在這個地方。

     

  •  
  • 更新python的軟連接:

rm -rf /usr/bin/python3

ln -s /usr/local/bin/python3.6 /usr/bin/python3

  • 驗證

python3 -V

4、安裝uWSGI

  • 安裝 pip3 install uwsgi 
  • 報這個錯已經在前面的步驟解決
  • plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
         #include <Python.h>
                            ^
        compilation terminated.
        In file included from plugins/python/pyutils.c:1:0:
        plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
         #include <Python.h>
                            ^
        compilation terminated.
    

     

  • 驗證 
  • def application(env, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return [b"Hello Django"]
    uwsgi --http :8001 --wsgi-file test.py

    瀏覽器訪問,網頁能顯示 Hello Django 那麼就沒問題

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