1. Location of site-packages folder
When we install a Python package through pip or other means, the files of these packages will be copied to the site-packages folder.
The site-packages folder is usually located in the Lib folder under the Python installation directory. The specific paths will vary depending on the operating system you are using and the Python version. Here are the default locations of the site-packages folder under some common operating systems:
1.1. On Windows
.site-packages folder in the user directory:After installing Python, a hidden folder will be generated in the user directory, and the path is usually:
C:\Users\username\AppData\Roaming\Python\Python Version Number\site-packages
C:\Users\username\AppData\Local\Programs\Python\Python Version Number\Lib\site-packages.
This path is user-level, so the installation package path for each user may vary.
.site-packages folder in the system directory:This folder is located in the Python installation directory, usually C:\Python version number\Lib\site-packages. In this folder, some system-level Python packages are installed for sharing and use by all users.
1.2. On Linux or Mac
The site-packages folder is usually located in the lib folder at the root of Python. For example, in a general Python installation, the path to the site-packages folder might be: /usr/lib/python3/dist-packages/.
1.3. On the virtual environment (conda)
A virtual environment is a mechanism for isolating a Python environment, and can create multiple independent Python environments on the same machine. Each virtual environment will have its own independent .site-packages folder, which is used to store Python packages installed in that environment. .site-packages for virtual environments are usually Lib\site-packages in the virtual environment folder.
For example: D:*\anaconda3\envs\python310\Lib\site-packages.
2. Find the installation directory of site-packages
2.1. Using the site module
Python's standard library has a site module that helps you find the location of the site-packages directory.
import site print(())
This code outputs a list containing all site-packages directory paths.
> .\ ['D:\\programs\\anaconda3\\envs\\python310', 'D:\\programs\\anaconda3\\envs\\python310\\lib\\site-packages']
2.2. Using the distutils module
Another way to find the site-packages directory is to use the distutils module.
import print(.get_python_lib())
This outputs the default site-packages directory path.
> .\ D:\programs\anaconda3\envs\python310\Lib\site-packages
2.3. Through the command line
If you prefer to use the command line rather than writing code, you can find the site-packages directory using the following command:
> python -m site = [ 'D:\\works\\demo', 'D:\\programs\\anaconda3\\envs\\python310\\', 'D:\\programs\\anaconda3\\envs\\python310\\DLLs', 'D:\\programs\\anaconda3\\envs\\python310\\lib', 'D:\\programs\\anaconda3\\envs\\python310', 'D:\\programs\\anaconda3\\envs\\python310\\lib\\site-packages', ] USER_BASE: 'C:\\Users\\username\\AppData\\Roaming\\Python' (doesn't exist) USER_SITE: 'C:\\Users\\username\\AppData\\Roaming\\Python\\Python310\\site-packages' (doesn't exist) ENABLE_USER_SITE: True
refer to:
/kb/ask/
/baidu_22713341/article/details/139083851
This is the article about the methods and steps of python installation package site-packages. For more related contents of python installation package site-packages, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!