Deploying python applications windows

Deploying Python applications¶

Pynsist is a tool that bundles Python programs together with the Python-interpreter into a single installer based on NSIS. In most cases, packaging only requires the user to choose a version of the Python-interpreter and declare the dependencies of the program. The tool downloads the specified Python-interpreter for Windows and packages it with all the dependencies in a single Windows-executable installer.

The installed program can be started from a shortcut that the installer adds to the start-menu. It uses a Python interpreter installed within its application directory, independent of any other Python installation on the computer.

A big advantage of Pynsist is that the Windows packages can be built on Linux. There are several examples for different kinds of programs (console, GUI) in the documentation . The tool is released under the MIT-licence.

Application bundles¶

Windows¶

py2exe¶

py2exe is a distutils extension which allows to build standalone Windows executable programs (32-bit and 64-bit) from Python scripts. Python versions included in the official development cycle are supported (refers to Status of Python branches). py2exe can build console executables and windows (GUI) executables. Building windows services, and DLL/EXE COM servers might work but it is not actively supported. The distutils extension is released under the MIT-licence and Mozilla Public License 2.0.

Читайте также:  Скругление углов css код

macOS¶

py2app¶

py2app is a Python setuptools command which will allow you to make standalone macOS application bundles and plugins from Python scripts. Note that py2app MUST be used on macOS to build applications, it cannot create Mac applications on other platforms. py2app is released under the MIT-license.

Unix (including Linux and macOS)¶

pex¶

pex is a library for generating .pex (Python EXecutable) files which are executable Python environments in the spirit of virtualenvs. pex is an expansion upon the ideas outlined in PEP 441 and makes the deployment of Python applications as simple as cp. pex files may even include multiple platform-specific Python distributions, meaning that a single pex file can be portable across Linux and macOS. pex is released under the Apache License 2.0.

Configuration management¶

FIXME puppet salt chef ansible fabric 

Источник

Configure Python web apps for IIS

Applies to: yesVisual Studio noVisual Studio for Mac noVisual Studio Code

When using Internet Information Services (IIS) as a web server on a Windows computer (including Windows virtual machines on Azure), Python apps must include specific settings in their web.config files so that IIS can properly process Python code. The computer itself must also have Python installed along with any packages the web app requires.

Install Python on Windows

To run a web app, first install your required version of Python directly on the Windows host machine as described on Install Python interpreters.

Record the location of the python.exe interpreter for later steps. For convenience, you can add that location to your PATH environment variable.

Читайте также:  Событие ondblclick

Install packages

When using a dedicated host, you can use the global Python environment to run your app rather than a virtual environment. Accordingly, you can install all of your app’s requirements into the global environment simply by running pip install -r requirements.txt at a command prompt.

Set web.config to point to the Python interpreter

Your app’s web.config file instructs the IIS (7+) web server running on Windows about how it should handle Python requests through either HttpPlatform (recommended) or FastCGI. Visual Studio versions 2015 and earlier make these modifications automatically. When using Visual Studio 2017 and later, you must modify web.config manually.

Configure the HttpPlatform handler

The HttpPlatform module passes socket connections directly to a standalone Python process. This pass-through allows you to run any web server you like, but requires a startup script that runs a local web server. You specify the script in the element of web.config, where the processPath attribute points to the site extension’s Python interpreter and the arguments attribute points to your script and any arguments you want to provide:

The HTTP_PLATFORM_PORT environment variable shown here contains the port that your local server should listen on for connections from localhost. This example also shows how to create another environment variable, if desired, in this case SERVER_PORT .

Configure the FastCGI handler

FastCGI is an interface that works at the request level. IIS receives incoming connections and forwards each request to a WSGI app running in one or more persistent Python processes.

We recommend using HttpPlatform to configure your apps, as the WFastCGI project is no longer maintained.

Читайте также:  Built in classes in python

To use FastCGI, first install and configure the wfastcgi package as described on pypi.org/project/wfastcgi/.

Next, modify your app’s web.config file to include the full paths to python.exe and wfastcgi.py in the PythonHandler key. The steps below assume that Python is installed in c:\python36-32 and that your app code is in c:\home\site\wwwroot; adjust for your paths accordingly:

    Modify the PythonHandler entry in web.config so that the path matches the Python install location (see IIS Configuration Reference (iis.net) for exact details).

  • The value for PYTHONPATH may be freely extended but must include the root of your app.
  • WSGI_HANDLER must point to a WSGI app importable from your app.
  • WSGI_LOG is optional but recommended for debugging your app.

Second, add the following entry below the one for WSGI_HANDLER , replacing DjangoAzurePublishExample with the name of your project:

# Change the URL or IP address to your specific site ALLOWED_HOSTS = ['1.2.3.4'] 

Deploy to IIS or a Windows VM

With the correct web.config file in your project, you can publish to the computer running IIS by using the Publish command on the project’s context menu in Solution Explorer, and selecting the option, IIS, FTP, etc.. In this case, Visual Studio simply copies the project files to the server; you’re responsible for all server-side configuration.

Feedback

Submit and view feedback for

Источник

Оцените статью