How to Use SAE to deploy the Python Runtime Environment

Source: Internet
Author: User

How to Use SAE to deploy the Python Runtime Environment

This article mainly introduces how to use SAE to deploy the Python runtime environment. As an online software deployment platform of Sina, SAE has a certain cost-effectiveness in China. If you need it, refer to it.

Because GAE is inconvenient to access in China, I usually put some small applications on SAE. Although SAE has many defects, it is easy to get started, at least the document is well written.

I usually use Flask to develop applications on SAES. SAE is pre-installed with Flask, so you can use it directly, but we will inevitably use some libraries without pre-installed ones.

In the past, you may need to copy the package to the application directory by yourself, and then manually load the package. Now, you don't need to worry about it. SAE has a very good solution, see install third-party packages on dependencies

You can use saecloud to install third-party libraries instead of pip

?

1

Saecloud install-r requirements.txt

This command installs a third-party library under the site-packages directory of the application directory. during deployment, all dependencies can be packaged into zip files, which makes uploading and maintenance easy.

?

1

2

Cd site-packages/

Zip-r ../site-packages.zip.

Load these dependencies in index. wsgi

?

1

2

3

4

5

6

7

8

Import OS

Import sys

 

Root = OS. path. dirname (_ file __)

 

# One of the two

Sys. path. insert (0, OS. path. join (root, 'site-packages '))

Sys. path. insert (0, OS. path. join (root, 'site-packages.zip '))

Although either of them is preferred, it is recommended that you use zip files.

One problem is that we need to package, but SAE does not have pre-installed packages, but we need to rely on Flask to install these pre-installed packages using saecloud, this package is obviously redundant.

Considering the advantages of dependency management of bower and npm Package Manager, we should obviously separate the dependent libraries.

?

1

2

3

4

# Install non-preinstalled Dependencies

Pip install-r requirements.txt

# Maintaining pre-installed Dependencies

Saecloud install-r requirements-dev.txt

In this way, only the packages in requirements.txt will be installed in the site-packages folder under the application directory.

After some practices, I sorted out my own handy source code file structure.

Copy the Code as follows:

LICENSE

Makefile

README. md

Requirements-dev.txt

Requirements.txt

Site-packages

...

Site <--- web app directory

Index. wsgi

Main. py

Config. yam

Site-packages.zip <--- package dependency Library

...

I will add the following files to. gitignore to prevent them from being submitted to the version.

Copy the Code as follows:

/Site-packages

/Site/site-packages.zip

/Site/index. wsgic

To facilitate the installation of dependencies and deployment projects, I wrote a Makefile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.