Skip to content

Instantly share code, notes, and snippets.

@lizhiyong2000
Last active May 14, 2019 06:07
Show Gist options
  • Save lizhiyong2000/cadc9d2d4059adcc726428765806456d to your computer and use it in GitHub Desktop.
Save lizhiyong2000/cadc9d2d4059adcc726428765806456d to your computer and use it in GitHub Desktop.
get python sitepackages locations
import subprocess
import json
def get_python_sitepackages():
cmd = 'python3 -c "import site; print(site.getsitepackages())"'
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
out = s.stdout.read().decode("utf-8")
s.stdout.close()
result = json.loads(out.replace("'", '"'))
cmd = 'python3 -m site --user-site'
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
out = s.stdout.read().decode("utf-8")
s.stdout.close()
result.append(out.strip())
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment