我想看看pip源代码,因为我想知道pip install命令是如何工作的!
当您使用命令"pip intall xxx.tar.gz“或"pip install xxx”时,它是不同的。"pip intall xxx.tar.gz“可能会在你的PC目录中搜索并解压文件,然后运行"python setup.py build->python setup.py install”。但是"pip install xxx“将默认在"https://pypi.org/simple”中搜索xxx,并下载目标包。当然,这只是我的猜测。
我需要看看源代码。我在哪里可以找到它?看到站点-packages\pip了吗?
发布于 2021-06-29 11:27:16
下面是它的工作原理。Pip提供了一种使用setup.py文件在本地安装用户自定义项目的方法。此方法要求python项目具有以下文件结构:
example_project/
├── exampleproject/ Python package with source code.
| ├── __init__.py Make the folder a package.
| └── example.py Example module.
└── README.md README with info of the project.
Within this structure, user can add setup.py to the root of the project (i.e. example_project for above structure) with the following content:
from setuptools import setup, find_packages
setup(
name='example', # Name of the package. This will be used, when the project is imported as a package.
version='0.1.0',
packages=find_packages(include=['exampleproject', 'exampleproject.*']) # Pip will automatically install the dependences provided here.
)在此之后,pip可以通过从项目根目录运行以下命令来安装此自定义项目:
pip install -e。
来源-here
完整的代码可以在here中找到
发布于 2021-06-29 11:46:51
我太愚蠢了,忘记了维基百科和GitHub。pypi也有源代码url链接和文档链接。pc中的\Lib\site-package\pip与source code in github相同。
https://stackoverflow.com/questions/68172205
复制相似问题