--- third_party/python/virtualenv/virtualenv.py.orig 2021-02-01 22:20:21.000000000 -0600 +++ third_party/python/virtualenv/virtualenv.py 2021-02-01 22:28:31.000000000 -0600 @@ -1339,6 +1339,14 @@ "have Apple's development tools installed") raise + # For macOS on arm64, the copied binary needs to be ad-hoc codesigned. + + if os.uname()[4] == 'arm64': + codesign_cmd = ["codesign", "--sign", "-", "--force", + "--preserve-metadata=entitlements,requirements,flags,runtime", py_executable] + subprocess.call(codesign_cmd) + + if not is_win: # Ensure that 'python', 'pythonX' and 'pythonX.Y' all exist py_exe_version_major = 'python%s' % sys.version_info[0]