Python PIP:PIP安装找不到满足要求的版本 - 尽管存在于pyproject.toml中

发布于 2025-02-13 19:32:09 字数 2084 浏览 0 评论 0 原文

Python3 PIP错误 +诗歌包装

我正在尝试发布到TestPypi的Python库中。到目前为止,出版我的诗歌的构建还没有问题。

对于上下文,作为初学者,我来自这些网站:

  1. https://python-poetry.org/docs/ < /a>

出现的唯一问题是我的pyproject.toml中列出的依赖项使用PIP安装安装软件包时未考虑。

我试图更新 setuptools pip ,但我这样做了。

我的目标是在没有版本控制错误的情况下进行清洁依赖性安装。

this 是我尝试过的主要解决方案。

pyproject.toml

i隐​​藏了我的真实姓名。

[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"

在安装程序通过依赖项迭代时,它将根据首先订购的任何一个订购,返回此错误。 (在我的猴子斑点般的尝试修复此问题的过程中,我能够通过修改每个依赖项版本的严格性来更改安装顺序

错误pip返回

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
  • 我尝试更改严格性版本。 (我删除了 ^)
  • 作为经理的转为诗歌也是一次尝试。我以前的尝试是手册。
  • 我已经证实了这些构建与先前发布的正确构建相对应。

有关额外的信息:我正在基于 18.04.1-ubuntu 的GitHub Codespace上构建,

任何人是否有任何知识可以备用此类问题?我是包装和建造的新手,除了依赖关系外,我在大多数地方都取得了一些成功。

Python3 Pip error + Poetry Packaging

I am working in a python library that I am trying to publish to TestPypi. 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/
  2. 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.

I have attempted at updating setuptools and pip but I have done so to no avail.

My goal is to have clean dependency installation without the versioning errors.

This is the main solution I have tried.

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖阳 2025-02-20 19:32:09

主要错误

tldr; PIP试图用TestPypi解决依赖性,但它们在另一个索引(PYPI)中。答案结束时解决方法。

我发布到 testpypi 的事实是发生这种情况的原因。我将解释为什么我所做的错误会出现,然后我将展示您将来如何解决这个问题。

pypi 和testpypi

pypi 之间的差异是Python包装指数。这是Python软件包的巨型索引,可以使用 pip install 安装。
TestPypi 是指定用于测试和发布的Python软件包索引,而无需触摸真实的软件包索引。在学习如何发布软件包时,它可能很有用。主要区别是它是一个完全独立的存储库。因此, testpypi 上的内容可能不是 pypi 上的内容。
我的研究有限,因此,如果我使任何人感到困惑,主要区别是它们是两个不同的软件包索引。一个是出于测试目的。

我将软件包发布到 testpypi 上,并将我的 pip install 设置为从该存储库安装。 不是 pypi ,而是 testpypi

为什么当我定义项目的依赖关系时,依赖性解决方案失败

,我根据PYPI的存在定义了它们。大多数依赖项都存在于PYPI中。 不是 testpypi。这意味着,当我从testpypi中要求我的软件包时,PIP只会查看testPypi,而PIP安装程序工作流则落入了这样的模式:

0.5。将获取存储库设置为testpypi和不是 pypi。

  1. 从testpypi
  2. 安装中拉软件包并检查依赖项
  3. 找到第一个依赖关系(例如BeautifulSoup4)
  4. 从testpypi中
  5. 成功安装BeautifulSoup44
    - 。这是因为BeautifureSoup4 实际上是在TestPypi中存在的。
  6. 转移到另一个依赖性(例如Rich)
  7. 无法从TestPypi中拉出
    - 。 TestPypi中不存在Rich。
  8. 找不到返回依赖。

为什么某些依赖性正如您在工作流程步骤 5中看到的奇怪作用。

beautifulsoup4 包装在TestPypi上找到。 (有人把它放在那里)。

但是,正如您在步骤 7中看到的。之所以发生此问题,是因为我将仓库设置为从testpypi安装,因为我的包裹的位置。这导致PIP使用testpypi。对于每个依赖性也是如此。

我如何解决。

我通过使用TestPypi来验证准确的构建伪像出版,然后跳到正常 pypi来测试安装和依赖安装。

解决方法

从testpypi

python3 -m pip install -i https://test.pypi.org/simple/simple/&lt; package name&gt;

install from pypi(默认情况>

python3 -m python3 -m pip install install &lt;软件包名称&gt;

testPypi的安装软件包,但pypi的依赖项

python docs docs很好地解释了这一点。

如果要允许PIP还从PYPI下载软件包,则可以指定-Extra-index-url指向PYPI。当您要测试的软件包具有依赖项时,这很有用:

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

Main Error

TLDR; Pip tries to resolve dependencies with TestPypi, but they are in another index (Pypi). Workarounds at end of answer.

The fact that I am publishing to TestPypi is the reason this has happened. 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 is the Python Package Index. It's a giant index of Python packages one may install from with pip install.
TestPypi is the Python Package Index designated for testing and publishing without touching the real Package Index. 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.
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. Not Pypi, but TestPypi.

Why dependency resolution failed

When I defined my project's dependencies, I defined them based off of their Pypi presences. Most dependencies are present in Pypi. Not 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:

0.5. Set fetching repository to TestPypi and Not Pypi.

  1. Pull package from TestPypi
  2. Install and examine dependencies
  3. Find first dependency (e.g. Beautifulsoup4)
  4. Pull dependency from TestPypi
  5. Successfully install Beautifulsoup4
    -. This is because beautifulsoup4 is actually present in the TestPypi.
  6. Move on to another dependency (e.g. rich)
  7. Fail to pull from TestPypi
    -. Rich is not present in 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. (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. This issue occurs because I set my repoistiroy to install from TestPypi because my that is where my package was held. This caused pip to use 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.

Workarounds

Install from TestPypi

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

Install from Pypi (by default)

python3 -m pip install <package name>

Install package from TestPypi but dependencies from Pypi

The Python Docs explains this very well.

If you want to allow pip to also download packages from PyPI, you can specify --extra-index-url to point to 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文