📜  gunicorn windows (1)

📅  最后修改于: 2023-12-03 15:31:05.310000             🧑  作者: Mango

Gunicorn on Windows

Gunicorn is a popular Python WSGI HTTP Server for UNIX systems. However, it is also possible to run Gunicorn on Windows. In this article, we will explore the steps required to install and use Gunicorn on Windows.

Requirements
  • Python 2.7 or Python 3.4+
  • Pip
  • Virtualenv (optional)
Installation
  1. Install Python by downloading and running the installer from the official website: https://www.python.org/downloads/windows/
  2. Open command prompt and install pip by running the following command:
python -m ensurepip
  1. Install virtualenv by running the following command:
pip install virtualenv
  1. Create a virtual environment by running the following command:
virtualenv myenv
  1. Activate the virtual environment by running the following command:
.\myenv\Scripts\activate
  1. Install Gunicorn by running the following command:
pip install gunicorn
Running Gunicorn

To run Gunicorn, you need to create a Python WSGI application. This can be done in a separate file, for example app.py, as shown below:

def app(environ, start_response):
    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    response_body = 'Hello, World!'
    start_response(status, headers)
    return [response_body.encode()]

Next, you can start Gunicorn by running the following command:

gunicorn app:app

This will start Gunicorn and listen on the default port 8000. You can access your application by opening a web browser and navigating to http://localhost:8000.

Conclusion

In this article, we have explored the steps required to install and use Gunicorn on Windows. By following these steps, you can now run Python WSGI applications on Windows using Gunicorn.