1

i want to remove my source code .py files to avoid rivals to see my code.

so i use

python -c "import compileall; compileall.compile_dir('D:/acc')"

to compile all py files to pyc,next step is to remove py files,and run the project only use pyc, how to do it?

Max
  • 7,957
  • 10
  • 33
  • 39

2 Answers2

6

you can use shutils, which is in the standard lib but please consider that removing *.py files is not a very string protection as it is very easy to rebuild the *.py file from a *.pyc.

Using py2exe with a drm packer would be much more secure.

LBarret
  • 1,113
  • 10
  • 23
  • i know but first, the project will be running on linux,windows only for a test,second pyc is enough for my case – Max Sep 06 '12 at 10:14
2

One convenient approach is to rename the main module pyc file to __main__.pyc and put all pyc files in a zip file. Python 2.6 and above are then able to run the zip:

python myapplication.zip

Be aware that pyc files are not compatible between different Python versions.

Janne Karila
  • 24,266
  • 6
  • 53
  • 94
  • can you tell it in details? i renamed my entry pyc file to __main__.pyc as you said and package the whole package to a zip file.but when i run the zip file python told me can't find __main__ module – Max Sep 06 '12 at 10:55
  • What you did sounds right. One possible cause to that error message is trying to use a different Python version to run. Python will look for the corresponding .py file if the .pyc file is not compatible, and complain. – Janne Karila Sep 06 '12 at 11:03