import re
import os
import site
import sys
if sys.version_info[:2] != (3, 14):
exit(f'Your PYTHONPATH points to a site-packages dir for Python 3.14 '
f'but you are running Python {sys.version_info[0]}.{sys.version_info[1]}!\n'
f' PYTHONPATH is currently: "{os.environ["PYTHONPATH"]}"\n'
f' You should `unset PYTHONPATH` to fix this.')
if os.path.realpath(sys.executable).startswith('/opt/homebrew/Cellar/python@3.14'):
library_site = '/Library/Python/3.14/site-packages'
library_packages = [p for p in sys.path if p.startswith(library_site)]
sys.path = [p for p in sys.path if not p.startswith(library_site)]
sys.path.extend(library_packages)
long_prefix = re.compile(r'/opt/homebrew/Cellar/python@3.14/[0-9\._abrc]+/(?:Frameworks/Python\.framework/Versions/3.14/)?lib/python3.14/site-packages')
sys.path = [long_prefix.sub('/opt/homebrew/lib/python3.14/site-packages', p) for p in sys.path]
if 'PYTHONEXECUTABLE' not in os.environ and sys.prefix == sys.base_prefix:
sys.executable = sys._base_executable = '/opt/homebrew/opt/python@3.14/bin/python3.14'
if 'PYTHONHOME' not in os.environ:
cellar_prefix = re.compile(r'/opt/homebrew/Cellar/python@3.14/[0-9\._abrc]+(?=/|$)')
if os.path.realpath(sys.base_prefix).startswith('/opt/homebrew/Cellar/python@3.14'):
new_prefix = cellar_prefix.sub('/opt/homebrew/opt/python@3.14', sys.base_prefix)
site.PREFIXES[:] = [new_prefix if x == sys.base_prefix else x for x in site.PREFIXES]
if sys.prefix == sys.base_prefix:
sys.prefix = new_prefix
sys.base_prefix = new_prefix
if os.path.realpath(sys.base_exec_prefix).startswith('/opt/homebrew/Cellar/python@3.14'):
new_exec_prefix = cellar_prefix.sub('/opt/homebrew/opt/python@3.14', sys.base_exec_prefix)
site.PREFIXES[:] = [new_exec_prefix if x == sys.base_exec_prefix else x for x in site.PREFIXES]
if sys.exec_prefix == sys.base_exec_prefix:
sys.exec_prefix = new_exec_prefix
sys.base_exec_prefix = new_exec_prefix
if sys.base_prefix in site.PREFIXES:
site.PREFIXES.insert(site.PREFIXES.index(sys.base_prefix), '/opt/homebrew')
site.addsitedir('/opt/homebrew/lib/python3.14/site-packages')
for split_module in ["tk", "gdbm"]:
split_prefix = f"/opt/homebrew/opt/python-{split_module}@3.14/libexec"
if os.path.isdir(split_prefix):
sys.path.append(split_prefix)