Python Falcon - 環境搭建



最新版本的 Falcon 需要 Python 3.5 或更高版本。最簡單也是推薦的安裝 Falcon 的方法是使用 PIP 安裝程式,最好是在虛擬環境中。

可以透過執行以下命令安裝最新穩定版本:

pip3 install falcon

要驗證安裝是否成功,請匯入庫並檢查其版本。

>>> import falcon
>>>falcon.__version__
'3.1.0'

要安裝最新的 Beta 版本,應使用以下命令:

pip3 install --pre falcon

從早期版本開始,Falcon 就支援 WSGI。可以使用 Python 標準庫模組wsgiref中的內建 WSGI 伺服器執行 Falcon 應用。但是,它不適合生產環境,生產環境需要 gunicorn、waitress 或 uwsgi 等 WSGI 伺服器。

對於 Windows 上的 Falcon,可以使用Waitress,這是一個生產級的純 Python WSGI 伺服器。像往常一樣,使用 pip 安裝程式安裝它。

pip3 install waitress

Gunicorn伺服器無法安裝在 Windows 上。但是,它可以在 Windows 10 的 Windows 子系統 Linux (WSL) 環境中使用。要在 Linux、WSL 或 Docker 容器中使用 gunicorn,請使用

pip3 install gunicorn

如果要執行非同步 Falcon 應用,則需要一個符合 ASGI 的應用伺服器。Uvicorn 伺服器可以在 Windows 和 Linux 系統上使用。

pip3 install uvicorn
廣告
© . All rights reserved.