문제

Is there cross-platform way to get default directory for console scripts the same way one can use sys.executable to get path to the Python's interpreter in cross-platform way?

Context:
There's Python script which runs various tools like pip using subprocess module and it would be good to make sure to run tools that accompany Python's interpreter used to run this script. Please note that the script may be run from within virtualenv which had not been activated – ./venv/bin/python script.py

올바른 솔루션이 없습니다

다른 팁

Yes, sysconfig module provides such API through get_path() function:

Linux:

pdobrogost@host:~/tmp$ venv/bin/python -c "import sysconfig; print(sysconfig.get_path('scripts'))"
/home/users/pdobrogost/tmp/venv/bin

Windows:

X:\>venv\Scripts\python.exe -c "import sysconfig; print(sysconfig.get_path('scripts'))"
X:\venv\Scripts

References:
https://groups.google.com/forum/#!topic/comp.lang.python/s3vLkVy2xJk
https://mail.python.org/pipermail/distutils-sig/2014-February/023867.html

Thank you Ned Batchelder, Oscar Benjamin, Paul Moore and Vinay Sajip for help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top