Use Cython to protect Python code __python

Source: Internet
Author: User
Tags in python

Programs written in Python are typically published in the source code, so what if you don't want others to see the content?

The first method is to compile the code into a byte code, which is PYc file.

Executive: Python-m py_compile <filename>.py


Although this method can also hide the source code, but in fact can be decompile.


The second way is to use Cython to turn Python code into C language code and compile it into an executable program.

Method:

Install Cython First

Pip Install Cython

Installing the Python Development Kit

CentOS System: Yum install Python-devel

Ubuntu System: sudo apt-get install Python-dev


Convert Python code to C code:

Cython hello.py--embed

This will generate a hello.c C-language source file

Then use GCC to compile the binary executable, which requires the development of header files, compilation options, link Options


CentOS system: GCC ' python-config--cflags ' python-config--ldflags ' Hello.c-o Hello

If the Python version is high, you can use gcc ' python3-config--cflags--ldflags ' Hello.c-o Hello


So the code is compiled into a binary executable program.


Try to link the wrong words:

GCC ' python-config--cflags '-o hello hello.c ' python-config--ldflags '

Reference

If you are prompted for a connection error, the solution is here: http://stackoverflow.com/questions/13782618/python-py-initialize-unresolved-during-compilation



Related Article

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.