# How to hide python code using CMakeList

**URL:** <https://discourse.slicer.org/t/how-to-hide-python-code-using-cmakelist/40720>\
**Category:** Support\
**Tags:** build, python\
**Created:** [December 16, 2024, 8:29pm UTC](https://discourse.slicer.org/t/how-to-hide-python-code-using-cmakelist/40720 "2024-12-16T20:29:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvinsuzuki](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/calvinsuzuki/32/69398_2.png) [@calvinsuzuki](https://discourse.slicer.org/u/calvinsuzuki)\
**Post date:** [December 16, 2024, 8:29pm UTC](https://discourse.slicer.org/t/how-to-hide-python-code-using-cmakelist/40720/1 "2024-12-16T20:29:47Z")

</div>

Hey everyone,  
I’m confused about python code obfuscation.

[This matter was already discussed on the community  
 ](https://discourse.slicer.org/t/how-to-hide-the-code-of-the-script-module/26135)

But I couldn’t see how to do it. Which CMakeList should I configure? And when this should be executed? I’m not familiar with any kind of module installation/build. I’m running Slicer on Ubuntu 20.04

Some interesting links were provided, such as [this one](https://github.com/search?q=repo%3ASlicer%2FSlicer%20.pyc&type=code) and the following CMakeList code block:

```auto
function(replace_py_with_pyc ${SCRIPTED_MODULE_PYCACHE_DIR_PATH})
  if (EXISTS ${SCRIPTED_MODULE_PYCACHE_DIR_PATH}/ __pycache__ AND IS_DIRECTORY ${SCRIPTED_MODULE_PYCACHE_DIR_PATH}/ __pycache__ )
    message("--- Attempting to copy .pyc files...")
    file(GLOB PYC_FILES ${SCRIPTED_MODULE_PYCACHE_DIR_PATH}/ __pycache__ /*.pyc)
    file(COPY ${PYC_FILES} DESTINATION ${SCRIPTED_MODULE_PYCACHE_DIR_PATH}/)

    message("--- Attempting to remove .py files...")
    file(GLOB PY_FILES ${SCRIPTED_MODULE_PYCACHE_DIR_PATH}/*.py)
    file(REMOVE ${PY_FILES})
  endif()

  file(GLOB SUBDIRS LIST_DIRECTORIES True ${SCRIPTED_MODULE_PYCACHE_DIR_PATH}/*)
  foreach(subdir ${SUBDIRS})
    replace_py_with_pyc(${subdir})
  endforeach()

  message("--- Done copying .pyc files.")
endfunction()

replace_py_with_pyc(${Slicer_INSTALL_QTSCRIPTEDMODULES_LIB_DIR})

```

Can anyone give me a documentation or a guide to help me generate \*.pyc and remove \*.py of my module? I tried to simply substitute the files, using \*.pyc and \*.cpython-39.pyc, but it didn’t worked.
