【问题标题】:Poetry already added module, but not installed诗歌已添加模块,但未安装
【发布时间】:2020-12-16 12:22:06
【问题描述】:

我的pyproject.toml 是这样的

[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.19.4"
pandas = "^1.1.5"
matplotlib = "^3.3.3"
seaborn = "^0.11.0"
lightgbm = "^3.1.1"
jupyter = "^1.0.0"
notebook = "^6.1.5"
.
.
.
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

poetry install 并打开 python 后,我发现我可以导入一些模块(numpy 和 pandas),但不能导入其他模块,如 seaborn、lightgbm 等。 任何人都知道如何解决这个问题? 我遇到了同样的情况,所以我手动删除了.venvpoetry.lock。然后我通过poetry install 重新添加了模块。但这并不顺利...

$ poetry run python
Python 3.9.1 (default, Dec 10 2020, 10:36:35)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import numpy
>>> import pandas

>>> import seaborn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'seaborn'

>>> import lightgbm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lightgbm'

我猜llvmlite 是这个问题的主要原因,所以我会努力寻找解决方案。但如果你已经知道,请分享。

$ poetry cache clear pypi --all
$ rm -r .venv
$ rm poetry.lock
$ poetry install

### a lot of process goes on

  • Installing colorama (0.4.4): Installing...
  • Installing llvmlite (0.35.0rc3): Failed
  • Installing llvmlite (0.35.0rc3): Failed
  • Installing colorama (0.4.4)
  • Installing llvmlite (0.35.0rc3): Failed
  RuntimeError
  Unable to find installation candidates for llvmlite (0.35.0rc3)
  at /usr/local/Cellar/poetry/1.1.4/libexec/lib/python3.9/site-packages/poetry/installation/chooser.py:72 in choose_for
       68│
       69│             links.append(link)
       70│
       71│         if not links:
    →  72│             raise RuntimeError(
       73│                 "Unable to find installation candidates for {}".format(package)
       74│             )
       75│
       76│         # Get the best link

以下是可能的解决线索

诗歌回复它已经安装了。

$ poetry add seaborn
The following packages are already present in the pyproject.toml and will be skipped:

  • seaborn

If you want to update it to the latest compatible version, you can use `poetry update package`.
If you prefer to upgrade it to the latest available version, you can use `poetry add package@latest`.

Nothing to add.
$ poetry run which python

/Users/<user>/.venv/bin/python
$ poetry env info

Virtualenv
Python:         3.9.1
Implementation: CPython
Path:           /Users/<user>/.venv
Valid:          True

System
Platform: darwin
OS:       posix
Python:   /usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9
$ poetry -V

Poetry version 1.1.4

【问题讨论】:

  • 如果你能把它缩小到minimal reproducible example,那会更容易回答。
  • 谢谢。在这个问题之前我遇到了很多问题,我感到很苦恼。我将确定主要问题是什么,稍后再修改这个问题。

标签: python virtual-environment python-poetry


【解决方案1】:

我解决了这个问题。这个问题只是关于安装llvmlite的失败,而不是诗歌。 llvmlite 是安装 pandas-profiling 的先决条件,我正在尝试安装。

寻找依赖问题的经验法则

  1. 删除当前环境
$ poetry cache list
# after finding out what cache exists
$ poetry cache clear <cache name> --all
$ rm -r .venv
$ rm poetry.lock 
  1. 记下您已安装的模块或副本
$ cat pyproject.toml
# take a note or copy of what modules you have installed

$ rm pyproject.toml
  1. 重新初始化环境并逐步添加模块
$ poetry init
# not adding modules except ones you are sure not to cause problem

$ poetry add <module>
  1. 找出真正的问题

【讨论】:

  • poetry show --tree 会显示一个依赖树:)
猜你喜欢
  • 1970-01-01
  • 2022-08-11
  • 2016-08-14
  • 1970-01-01
  • 2012-03-05
  • 2020-12-25
  • 2017-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多