Search code examples
python-3.xinputexecx-freeze

Hide input files during the conversion of python scripts into exe


I have python scripts in folder A and some dependent input files (.xlsx,.txt) in folder B. I am using cx_Freeze to convert them into exe. I have the files in the folder B as a list in include_files in setup.py During the conversion, the files fall in the build folder. The files should not be visible to the user, or at least they should be only in read-only mode.


Solution

  • You can use os.chmod at the end of your setup script to make any file of the build directory read-only. For example:

    import os
    import stat
    os.chmod(path_to_file, stat.S_IREAD)
    

    Of course you need to know the path to the build directory. You can also tell cx_Freeze which directory to use as build directory by using the build_exe option of the build_execommand, see the cx_Freeze documentation.