Skip to content

Instantly share code, notes, and snippets.

@pcotret
Last active April 24, 2023 15:32
Show Gist options
  • Save pcotret/4f52eabda537c87790f08147d996303c to your computer and use it in GitHub Desktop.
Save pcotret/4f52eabda537c87790f08147d996303c to your computer and use it in GitHub Desktop.
The idea is to get rid of distutils which is deprecated in Python 3.10 and normally removed in Python 3.12. For instance, it's used in Capstone disassembly engine.
def get_site_packages(): # pragma: no cover
try:
paths = site.getsitepackages()
if site.ENABLE_USER_SITE:
paths.append(site.getusersitepackages())
return paths
except Exception:
try:
from distutils.sysconfig import get_python_lib
return [get_python_lib()]
# just incase, don't fail here, it's not worth it
except Exception:
return []
def get_site_packages_wo_distutils():
try:
paths = site.getsitepackages()
if site.ENABLE_USER_SITE:
paths.append(site.getusersitepackages())
return paths
except Exception:
try:
from sysconfig import get_path
return [get_path("platlib")]
# just incase, don't fail here, it's not worth it
except Exception:
return []
print(get_site_packages())
print(get_site_packages_wo_distutils())
@pcotret
Copy link
Author

pcotret commented Apr 24, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment