A tutorial on using the SAE to deploy Python to run the environment

Source: Internet
Author: User
Tags join zip

This article mainly introduces the use of SAE deployment Python running Environment tutorial, SAE as SINA's online software deployment platform, in the country has a certain price, the need for friends can refer to the

Because GAE in the domestic access inconvenience, so there are usually some small applications, I will put on the SAE above, although the SAE still have many defects, but it is easy to get started a, the minimum document written well.

Development SAE application, I generally use flask,sae pre-installed flask, so you can directly use, but we will inevitably use some not pre-installed library.

If it is in the past, you may need to copy the package to the application directory, and then manually load, now, do not need so much trouble, the SAE has a very good solution, see the installation of Dependent third Party package

You can use Saecloud instead of PIP to install a third-party library

?

1 Saecloud Install-r Requirements.txt

This command installs the Third-party library under the Site-packages directory of the application directory, and when deployed, it is convenient to upload and maintain all dependencies packaged into ZIP files.

?

1 2 CD Site-packages/zip-r ... /site-packages.zip.

Load these dependencies into the INDEX.WSGI

?

1 2 3 4 5 6 7 8 Import OS import sys root = Os.path.dirname (__file__) # both takes one Sys.path.insert (0, Os.path.join (root, ' site-packages ')) Sys.path.insert (0, Os.path.join (root, ' site-packages.zip '))

Although it is one of the two, learning is the recommended way to use zip files.

The problem is, we need to pack, but the SAE does not have pre-installed packages, but our local development depends on flask These pre-installed packages, all with Saecloud installation, this package is obviously redundant.

Using the benefits of Bower, NPM's dependency management for these package managers, we should obviously isolate the dependency library.

?

1 2 3 4 # Install non-pre-loaded dependent pip install-r requirements.txt # Maintenance pre-installed dependent Saecloud Install-r Requirements-dev.txt

This allows only packages in Requirements.txt to be installed in the Site-packages folder under the application directory.

After some practice, I sorted out my own use of a more comfortable source code file structure

Copy code 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 <---packaged dependent libraries

...

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

Copy code 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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.