"为什么pip不能成功安装Python和非Python文件?"

2024-10-03 02:46:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我的项目具有如下文件结构:

MyParserPkg/
  setup.py
  requirements.txt
  readme.txt
  MANIFEST.in
  doc/
  logs/

  ParserPKG/
  // many python files here
  parser.py
  config.a.ini
  config.b.ini

舱单内容为:

include README.txt requirements.txt
include ParserPkg/config.a.ini
include ParserPkg/config.b.ini

我的设置.py地址:

setup(name='ParserPkg', 
      version='0.1',
      description='A parser for testing',
      packages=['ParserPkg'],
      zip_safe=False)

然后我会:

pip install -r requirements.txt
pip install -e .

安装完成后,我检查了安装项目的虚拟环境的站点包,发现其中只包含一个文件:

my-envs/dialog-as-api/lib/python3.7/site-packages/ParserPkg.egg-link

以及此文件的内容,即我的项目的路径:

/Users/lvisa/MyParserPkg

为什么它只包含一个egg链接文件?你知道吗


Tags: pip文件项目pytxtconfigparser内容
2条回答

您使用的是-e标志,它使包可编辑。根据the documentation

“Editable” installs are fundamentally “setuptools develop mode” installs.

以下链接提供:

To do this, use the setup.py develop command. It works very similarly to setup.py install or the EasyInstall tool, except that it doesn’t actually install anything. Instead, it creates a special .egg-link file in the deployment directory, that links to your project’s source code. And, if your deployment directory is Python’s site-packages directory, it will also update the easy-install.pth file to include your project’s source code, thereby making it available on sys.path for all programs using that Python installation.

因此,它“安装”它的意义是,它可供任何其他模块使用,但它实际上并不复制文件,因此您可以编辑代码并立即测试它。你知道吗

pip install -e .以“可编辑”模式安装包。它会创建链接,并允许您编辑源代码而无需不断重新安装。你知道吗

所以你的软件包安装正确。这就是“可编辑”模式的工作原理。你知道吗

试试python -c 'import MyParserPkg'

相关问题 更多 >