Programmatically determine pip 'user install' location Scripts directory

后端 未结 2 2060
梦如初夏
梦如初夏 2020-12-21 15:27

As explained in pip\'s documentation a user can install packages in his personal account using pip install --user .

How can I programmatical

2条回答
  •  囚心锁ツ
    2020-12-21 15:33

    I believe the following should give the expected result

    import os
    import sysconfig
    
    user_scripts_path = sysconfig.get_path('scripts', f'{os.name}_user')
    print(user_scripts_path)
    

    But it might be that pip uses a different logic internally (probably based on distutils), but the results should still be the same.

    References

    • https://docs.python.org/3/library/sysconfig.html#installation-paths
    • https://docs.python.org/3/library/os.html#os.name

提交回复
热议问题