I’m trying to create a package in Python using Poetry and then use it in another project. However after importing the package, I’m unable to use it. The project doesn’t recognize it.
Library
pyproject.toml:
[tool.poetry]
name = "python-lib-example"
version = "0.5.0"
description = ""
authors = ["xxx"]
readme = "README.md"
packages = [{include = "python_lib_example"}]
[tool.poetry.dependencies]
python = "^3.12"
[tool.poetry.group.dev.dependencies]
devpi-client = "^7.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api
Test Class:
class PersonInfo:
def __init__(self, name, age):
self.name = name
self.age = age
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_info(self):
return f'{self.name} is {self.age} years old'
def __str__(self):
return self.get_info()
__init__.py
is empty
Project structure:
I build the package this way and upload it to DevPi, which is running in Docker. I then install it into the target project from DevPi.
Target project
pyproject.toml:
[tool.poetry]
name = "python-app-example"
version = "0.0.1"
description = ""
authors = ["xxx"]
readme = "README.md"
package-mode = false
[tool.poetry.dependencies]
python = "^3.12"
python-lib-example = {version = "^0.5.0", source = "mjana"}
[[tool.poetry.source]]
name = "mjana"
url = "http://localhost:3141/mjana/mjana/+simple"
priority = "supplemental"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api
And now I’m trying import
from python_lib_example import PersonInfo
But it seems that the project doesn’t recognize the package, even though the installation from DevPi completes without any issues. Where could I be making a mistake?