Use content sharing interfaces to reduce the size of Python applications __python

Source: Internet
Author: User
Tags git clone

In our previous article, "Using the platform interface provided by Ubuntu-app-platform to reduce QT application Size", we have learned how to use platform interface to reduce the size of QT applications. The implementation of this principle is to use content sharing to achieve. In today's tutorial, we use a Python interpreter snap installation package developed by developers themselves to achieve the same thing. For some systems, if you want to use the latest Python version, or if you want to use the same Python installation for a lot of Python applications, instead of having to break into the python environment into every single snap application package, we can use the method we're using today.

The entire source code for the snap application of this Python interpreter is:

Https://github.com/jhenstridge/python-snap-pkg

We can get it in the following ways:

$ git clone https://github.com/jhenstridge/python-snap-pkg


The source code for the whole project is as follows:

$ tree-l 3
.
├──examples
│└──hello-world
│     ├──hello.py
│     ├──hello.sh
│     └──snap
├──readme . MD
├──snap
│└──snapcraft.yaml
└──src
    └──sitecustomize.py

The snap directory above describes how to share python with the content sharing interface for use by other developers. The developer has uploaded the compiled snap to our store. We can install them in the following ways:

$  Snap Install--edge Python36-jamesh

We can go directly to the Examples/hello-world directory to enter the following command:

$ snapcraft 
preparing to pull Hello-world pulling Hello-world preparing to build 
Hello-world 
Building Hello-world 
Staging hello-world 
priming hello-world snapping ' Hello-world 
' |                                                             
Snapped Hello-world_0.1_all.snap

We can see the produced. snap file. We can use the following command:

$ sudo snap install--dangerous Hello-world_0.1_all.snap

To install this application. and use the following commands to connect and run:

$ snap Connect Hello-world:python3 python36-jamesh:python3
$ hello-world
Hello world!

We can see that our Hello-world application is running successfully.

hello.py

Print ("Hello world!")

We can check our final hello-world_0.1_all.snap file size:
$ ls-alh Total
28K
drwxrwxr-x 3 liuxg liuxg 4.0K March   1 09:45.
Drwxrwxr-x 3 liuxg liuxg 4.0K March   1 09:19.
-rw-rw-r--1 liuxg liuxg   28 March   1 09:19 gitignore-rw-rw-r--
1 liuxg liuxg   22 March   1 09:19 hello.py< C14/>-rwxrwxr-x 1 liuxg liuxg   60 March   1 09:19 hello.sh
-rw-r--r--1 liuxg liuxg 4.0K March   1 09:39 hello-wo Rld_0.1_all.snap
drwxrwxr-x 2 liuxg liuxg 4.0K March   1 09:23 Snap

The entire. snap file has only a small 4k size. This compares to the previous approach, and obviously this method of content sharing can greatly reduce the size of our Python application. Of course, this shared Python package can also be used for other Python applications.

You can even install your favorite PIP package in the following ways:

$ PYTHON36-JAMESH.PIP3 Install--user Django

The contents of this Django package will be installed into the $snap_user_common directory in the Python36-jamesh package.





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.