Lock a Python script so it cannot be edited

Last Published: April 25, 2020


Instructions provided describe how to lock a Python script so it cannot be edited. When scripts are going to be shared but the code needs to remain unchanged, compile the PY file into a PYC file. This ensures that the users are unable to make any changes to the existing code within the scripts. A PYC file is binary in nature and cannot be read directly.


Below is code that compiles a PY file into a PYC file.

PYC files run even if the PY files are not present.

import py_compile

script = "C:\\temp\\"

This code can be entered as its own PY file or can be entered into the Immediate Window of PythonWin.

The PYC file is created in the same directory as the PY file.

Article ID:000010321

  • ArcMap 9 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options