Poetry package `ImportError` even though package is already present

873 Views Asked by At

I'm using poetry for dependency management. I have poetry.lock file in my repository & I used it to install the dependencies using poetry install. It created a virtualenv and is activated.

# poetry env list
python-tricks-sYsxS0XS-py3.7 (Activated)

When I try to add numpy as a dependency, it gives ValueError: Package numpy is already present. However, when I try to import the numpy package in a shell or run a script containing numpy in it's import statements, it throws ModuleNotFoundError.

What I don't understand is, if the package is already present then why is it throwing ModuleNotFoundError?

Summary

poetry install -> Installs dependencies & created a virtualenv 

poetry env list -> Sanity check: python-tricks-sYsxS0XS-py3.7 (Activated)

poetry add numpy -> [ValueError]: Package numpy is already present

poetry scripty.py -> script.py imports numpy gives ModuleNotFoundError

Can someone provide an explanation for this behaviour and possible solution?

Note:- I have installed python using asdf

1

There are 1 best solutions below

0
On

As I mentioned I was using asdf. It has a plugin for poetry as well - https://github.com/crflynn/asdf-poetry

Using that solved the issue-

asdf plugin-add poetry
asdf install poetry # 1.0.10 is the latest
asdf local poetry 1.0.10

Poetry then works alright -

poetry add numpy