简体   繁体   English

Python Pip:pip install 找不到满足要求的版本 - 尽管存在于 pyproject.toml

[英]Python Pip: pip install cannot find a version that satisfies a requirement - despite present in pyproject.toml

Python3 Pip error + Poetry Packaging Python3 Pip 错误 + 诗歌打包

I am working in a python library that I am trying to publish to TestPypi.我正在尝试发布到 TestPypi 的 python 库中工作。 So far, there have been no issues with publishing my Poetry builds.到目前为止,发布我的诗歌版本没有任何问题。

For context, as a beginner, I come from these websites :对于上下文,作为初学者,我来自以下网站:

  1. https://python-poetry.org/docs/ https://python-poetry.org/docs/
  2. https://packaging.python.org/en/latest/tutorials/packaging-projects/ https://packaging.python.org/en/latest/tutorials/packaging-projects/

The only issue that has arose is that dependencies listed in my pyproject.toml are not accounted for when installing the package with pip install.出现的唯一问题是我的 pyproject.toml 中列出的依赖项在使用 pip install 安装包时没有考虑在内。

I have attempted at updating setuptools and pip but I have done so to no avail.我曾尝试更新setuptoolspip ,但这样做无济于事。

My goal is to have clean dependency installation without the versioning errors.我的目标是在没有版本控制错误的情况下进行干净的依赖安装。

This is the main solution I have tried. 是我尝试过的主要解决方案。

pyproject.toml pyproject.toml

I hid my real names.我隐藏了我的真实姓名。

[tool.poetry]
name = "package-name"
version = "0.1.0"
description = "<desc>"
authors = ["<myname> <myemail>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.10"
beautifulsoup4 = {version = "4.11.1", allow-prereleases = true}
recurring-ical-events = {version = "1.0.2b0", allow-prereleases = true}
requests = {version = "2.28.0", allow-prereleases = true}
rich = {version = "12.4.4", allow-prereleases = true}



[tool.poetry.dev-dependencies]
black = {version = "22.3.0", allow-prereleases = true}

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

As the installer iterates through a dependency, it will return this error depending on whichever one is ordered first.当安装程序遍历依赖项时,它将根据首先订购的那个而返回此错误。 ( Throughout my monkey-patch-like attempts at fixing this, I was able to change the order of installation by modifying the strictness of each dependency version ) 在我修复此问题的类似猴子补丁的尝试中,我能够通过修改每个依赖版本的严格性来更改安装顺序

the error pip returns错误点返回

ERROR: Could not find a version that satisfies the requirement requests==2.28.1 (from homeworkpy) (from versions: 2.5.4.1)
ERROR: No matching distribution found for requests==2.28.1
  • I have tried changing the strictness of the versions.我试过改变版本的严格性。 (I removed the ^) (我删除了^)
  • Switching to Poetry as a manager was also an attempt.转向诗歌作为经理也是一种尝试。 My previous attempts were manual.我以前的尝试是手动的。
  • I have verified that the builds are corresponding to the correct builds previously published.我已验证构建与先前发布的正确构建相对应。

For extra info: I am building on a Github Codespace in which I run on 18.04.1-Ubuntu更多信息:我正在构建一个 Github 代码空间,我在18.04.1-Ubuntu上运行

Would anyone have any knowledge to spare of an issue like this?会有人知道这样的问题吗? I am quite new to packaging and building, and I have had some success in most parts except for dependencies.我对打包和构建还很陌生,除了依赖项之外,我在大多数部分都取得了一些成功。

Main Error主要错误

TLDR; TLDR; Pip tries to resolve dependencies with TestPypi, but they are in another index (Pypi). Pip 尝试使用 TestPypi 解决依赖关系,但它们位于另一个索引 (Pypi) 中。 Workarounds at end of answer.答案结束时的解决方法。

The fact that I am publishing to TestPypi is the reason this has happened.我发布到TestPypi的事实是发生这种情况的原因。 I will explain why what I did made this error appear, and then I will show how you, from the future, may solve this.我将解释我所做的为什么会出现此错误,然后我将向您展示将来如何解决此问题。

Difference between Pypi and TestPypi Pypi和 TestPypi 的区别

Pypi is the Python Package Index. Pypi是 Python 包索引。 It's a giant index of Python packages one may install from with pip install .这是一个巨大的 Python 包索引,可以通过pip install TestPypi is the Python Package Index designated for testing and publishing without touching the real Package Index. TestPypi是 Python 包索引,指定用于测试和发布,而无需触及真正的包索引。 It can be useful in times when learning how to publish a package.在学习如何发布包时,它有时会很有用。 The main difference is that it is a completely separate repository.主要区别在于它是一个完全独立的存储库。 Therefore, what's on TestPypi may not be exactly what's on Pypi .因此, TestPypi上的内容可能不完全是Pypi上的内容。 My research was limited, so if I confused anyone, the main difference is that they are two different Package Indexes.我的研究很有限,所以如果我让任何人感到困惑,主要区别在于它们是两个不同的包索引。 One was made for testing purposes.一个是为了测试目的而制作的。

I published my package to TestPypi and set my pip install to install from that repository.我将我的包发布到TestPypi并将我的pip install设置为从该存储库安装。 Not Pypi , but TestPypi .不是Pypi ,而是TestPypi

Why dependency resolution failed为什么依赖解析失败

When I defined my project's dependencies, I defined them based off of their Pypi presences.当我定义项目的依赖项时,我根据它们的 Pypi 存在来定义它们。 Most dependencies are present in Pypi.大多数依赖项都存在于 Pypi 中。 Not TestPypi.不是TestPypi。 This meant that when I asked for my package from TestPypi, pip only looked at TestPypi, and the pip installer workflow fell out to a pattern like this:这意味着当我从 TestPypi 请求我的包时,pip 只查看了 TestPypi,并且 pip 安装程序的工作流程变成了这样的模式:

0.5. 0.5。 Set fetching repository to TestPypi and Not Pypi.将获取存储库设置为 TestPypi 而不是Pypi。

  1. Pull package from TestPypi从 TestPypi 拉包
  2. Install and examine dependencies安装和检查依赖项
  3. Find first dependency (eg Beautifulsoup4)查找第一个依赖项(例如 Beautifulsoup4)
  4. Pull dependency from TestPypi从 TestPypi 拉取依赖
  5. Successfully install Beautifulsoup4 -.成功安装 Beautifulsoup4 -. This is because beautifulsoup4 is actually present in the TestPypi.这是因为 Beautifulsoup4实际上存在于 TestPypi 中。
  6. Move on to another dependency (eg rich)转到另一个依赖项(例如,丰富的)
  7. Fail to pull from TestPypi -.无法从 TestPypi 中提取 -。 Rich is not present in TestPypi. Rich 在 TestPypi 中不存在。
  8. Return dependency not found.未找到返回依赖项。

Why some dependencies oddly worked为什么某些依赖项奇怪地起作用

As you see in workflow step 5. , the beautifulsoup4 package was found on the TestPypi.正如您在工作流程第5步中看到的那样,在 TestPypi 上找到了beautifulsoup4包。 (Someone had put it up there). (有人把它放在那里)。 image to TestPypi page with beautifulsoup4 However, as you see in step 7. , Rich is not found on the TestPypi index.使用 beautifulsoup4 将图像添加到 TestPypi 页面但是,正如您在步骤7中看到的那样,在 TestPypi 索引中找不到Rich This issue occurs because I set my repoistiroy to install from TestPypi because my that is where my package was held.出现此问题是因为我将我的 repoistiroy 设置为从 TestPypi 安装,因为我的包是存放在那里的。 This caused pip to use TestPypi.这导致 pip 使用 TestPypi。 for every single dependency as well.也适用于每一个依赖项。

How I got around it.我是如何绕过它的。

I got around it by using TestPypi to verify accurate build artifact publishing, and then I jumped to Normal Pypi to test installation and dependency installation.我通过使用 TestPypi 来验证准确的构建工件发布来解决这个问题,然后我跳到Normal Pypi 来测试安装和依赖项安装。

Workarounds解决方法

Install from TestPypi从 TestPypi 安装

python3 -m pip install -i https://test.pypi.org/simple/ <package name>

Install from Pypi (by default)从 Pypi 安装(默认)

python3 -m pip install <package name>

Install package from TestPypi but dependencies from Pypi从 TestPypi 安装包,但从 Pypi 安装依赖项

The Python Docs explains this very well. Python Docs 很好地解释了这一点。

If you want to allow pip to also download packages from PyPI, you can specify --extra-index-url to point to PyPI.如果你想允许 pip 也从 PyPI 下载包,你可以指定 --extra-index-url 指向 PyPI。 This is useful when the package you're testing has dependencies:当您正在测试的包具有依赖项时,这很有用:

python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ your-package

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

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