【发布时间】: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 等。
任何人都知道如何解决这个问题?
我遇到了同样的情况,所以我手动删除了.venv 和poetry.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