Tutorial on using SAE to deploy a python run environment

Source: Internet
Author: User
Because GAE in the domestic visit inconvenient, so there are some small applications, I will put on the SAE above, although the SAE has a lot of flaws, but it is easy to get started, at least the documentation is good.

Development of applications on the SAE, I generally use flask,sae pre-installed Flask, so you can use directly, but we will inevitably use some non-preloaded libraries.

If it was in the past, you might need to copy the package to the app directory yourself, and then load it manually, now, no need to be so troublesome, SAE has a very good solution, see "Install dependent third party package"

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

Saecloud Install-r Requirements.txt

This command installs the third-party library under the Site-packages directory of the application directory, where all dependencies can be packaged into a zip archive, so that it is easy to upload and maintain.

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

Load these dependencies in the Index.wsgi

Import Osimport sysroot = Os.path.dirname (__file__) # Take 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 it is one of the two, it is recommended to use a ZIP file.

One problem is that we need to pack, but the SAE does not have pre-packaged packages, but our local development also relies on Flask these preinstalled packages, all using Saecloud installation, this package will obviously have redundancy.

Drawing on the benefits of Bower, NPM, and the dependency management of these package managers, it is clear that we should separate the dependent libraries.

# Install non-preloaded dependent pip install-r requirements.txt# Maintenance Pre-installed dependency Saecloud install-r Requirements-dev.txt

This way, only the packages in the Requirements.txt will be installed in the Site-packages folder in the app directory.

After some practice, I have organized myself with the more comfortable source code file structure

The code is 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.

The code is 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.