简体   繁体   English

为什么pip无法成功安装python和非python文件?

[英]Why aren't python and non-python files installed successfully by pip?

My project has file structures like the following: 我的项目具有如下文件结构:

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

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

The content of MANIFEST is: 清单的内容是:

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

My setup.py: 我的setup.py:

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

Then I do: 然后我做:

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

After the installation, I then check the site-packages of my virtual environment in which the project was installed, and found that it only contains one file: 安装后,然后检查安装项目的虚拟环境的站点软件包,发现其中仅包含一个文件:

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

And the content of this file, which is the path of my project: 以及该文件的内容,这是我的项目的路径:

/Users/lvisa/MyParserPkg

Why does it only contain an egg-link file? 为什么只包含一个鸡蛋链接文件?

pip install -e . installs packages in "editable" mode. 以“可编辑”模式安装软件包。 It creates the link and allows you to edit your sources without constantly reinstalling. 它会创建链接,并允许您编辑源代码,而无需不断重新安装。

So your package is installed correctly. 因此,您的软件包已正确安装。 It's how "editable" mode works. 这就是“可编辑”模式的工作方式。

Try python -c 'import MyParserPkg' 试试python -c 'import MyParserPkg'

You're using the -e flag, which makes the package editable. 您正在使用-e标志,该标志使程序包可编辑。 As per the documentation , 根据文档

“Editable” installs are fundamentally “setuptools develop mode” installs. 从根本上来说,“可编辑”安装是“ setuptools开发模式”安装。

Following that link provides: 通过该链接可以提供:

To do this, use the setup.py develop command. 为此,请使用setup.py development命令。 It works very similarly to setup.py install or the EasyInstall tool, except that it doesn't actually install anything. 它与setup.py install或EasyInstall工具非常相似,但实际上并没有安装任何东西。 Instead, it creates a special .egg-link file in the deployment directory, that links to your project's source code. 而是在部署目录中创建一个特殊的.egg-link文件,该文件链接到项目的源代码。 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. 而且,如果您的部署目录是Python的site-packages目录,它还将更新easy-install.pth文件以包含您项目的源代码,从而使sys.path中的所有使用该Python安装的程序都可以使用它。

So it "installs" it in the sense that it's available for any other module to use, but it doesn't actually copy over the files, so that you can edit the code and test it out right away. 因此,它在某种意义上“安装”了它,可供其他任何模块使用,但实际上并没有覆盖文件,因此您可以编辑代码并立即对其进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM