Conventional python Packaging tools ( for example wheel), Yes, it will python The code enters a compressed package ( for example .tar.gz), And changed his name to .whl. Unpack during installation , Then the source code will be placed in site-package below , So for some needs python Code confidentiality is not applicable ..
When the source code needs to be kept secret , It can be considered to pass .pyc Instead of .py To provide services .
The following simple steps are explained :
from setuptools import setup,find_packages
import sys
import compileall
# Compile all the .py files under my_proj/m1.
# The pyc files get created in the same directory alongside the py file
compileall.compile_dir('dir')
# Not including the m1 directory in the packages, but including pyc patterns in
# package_data
setup(
name='my-pyapp',
version='0.0.1',
packages=find_packages(),
package_data={
'': ['dir/*.pyc'],
},
)
Through here package_data To introduce .pyc
Reference material :https://gist.github.com/raghavan97/9e1e6fadc838978666fd47a08c90ba95
3. perform
pip install wheel
python setup.py bdist_wheel
To create wheel package .
The current problems :.pyc After import , Can achieve import, however import The method of the completed object is inaccessible , The error information is as follows :
AttributeError: module 'xxx' has no attribute x'
Hello everyone , This is Wang
In the previous study , We hav