Last active
May 14, 2019 06:07
-
-
Save lizhiyong2000/cadc9d2d4059adcc726428765806456d to your computer and use it in GitHub Desktop.
get python sitepackages locations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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