【问题标题】:How do I install python packages with poetry?如何安装带有诗歌的 Python 包?
【发布时间】:2021-03-01 21:44:08
【问题描述】:

我正在将项目迁移到诗歌,但这里有一个问题。 这是一个简单的项目,不需要很多模块。我安装了诗歌,使用poetry add 添加了一些所需的包,然后运行了poetry install,但它似乎没有在我的venv 中安装pandas。我的pyproject.toml 看起来像这样:

[tool.poetry]
name = "***"
version = "0.1.0"
description = ""
authors = ["***"]

[tool.poetry.dependencies]
python = "^3.9"
pandas = "^1.2.2"
numpy = "^1.20.1"

[tool.poetry.dev-dependencies]

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

然后我运行:

PS C:\****> poetry install 
Installing dependencies from lock file

No dependencies to install or update

最后,当我想运行使用 pandas 的 main.py 脚本时,它说没有名为 pandas 的模块:

PS C:\***> python main.py
Traceback (most recent call last):
  File "C:\***\main.py", line 1, in <module>
    from output import QuestionnaireWrangler, PaymentProbabilityIndex
  File "C:\***\output.py", line 1, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

我在这里遗漏了一些谜题吗?

【问题讨论】:

    标签: python installation module package python-poetry


    【解决方案1】:

    poetry install 之后运行:

    poetry python main.py
    

    poetry shell
    python main.py
    

    对于生产,在您的 pyproject.toml 中添加以下行:

    [tool.poetry.scripts]
    my_app = 'mypackage.my_module:my_method'
    

    运行:

    poetry build
    

    之后:

    pip install my_project.whl # or tar  
    

    然后在 shell 或 bash 中运行 my_app

    希望对你有所帮助

    【讨论】:

      猜你喜欢
      • 2022-08-06
      • 2022-06-24
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 2021-10-17
      • 2020-05-05
      • 2022-06-28
      • 1970-01-01
      相关资源
      最近更新 更多