How do I install python packages with poetry?

Viewed 7991

Im migrating projects to poetry but have a problem here. This is simple project, not many modules needed. I installed poetry, used poetry add to add few packages required and then ran poetry install but it seems like its not installing pandas in my venv. My pyproject.toml looks like this:

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

Then I run:

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

No dependencies to install or update

And finally when I want to run main.py script which uses pandas it says there is no module named 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'

Am i missing some piece of puzzle here?

1 Answers

after poetry install run:

poetry python main.py

or

poetry shell
python main.py

for production add the follow lines in your pyproject.toml:

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

run:

poetry build

after:

pip install my_project.whl # or tar  

then run my_app in shell or bash

I hope I've helped

Related