Where does pip install its packages?

后端 未结 7 1741
野的像风
野的像风 2020-12-02 03:52

I activated a virtualenv which has pip installed. I did

pip3 install Django==1.8

and Django successf

7条回答
  •  猫巷女王i
    2020-12-02 04:20

    In a Python interpreter or script, you can do

    import site
    site.getsitepackages() # List of global package locations
    

    and

    site.getusersitepackages() # String for user-specific package location
    

    For locations third-party packages (those not in the core Python distribution) are installed to.

    On my Homebrew-installed Python on macOS, the former outputs

    ['/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages'],

    which canonicalizes to the same path output by pip show, as mentioned in a previous answer:

    $ readlink -f /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
    /usr/local/lib/python3.7/site-packages
    

    Reference: https://docs.python.org/3/library/site.html#site.getsitepackages

提交回复
热议问题