You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to import package with a name different from the project name #5744
I'm moving a library to use poetry. This library has a name that is different from the main package. It works well with setuptools and the function : packages=find_packages().
With poetry I have the following configuration:
But the package crossref is still not available for import.
for now I'm just trying to import the installed package.
importcrossref
Yes poetry install works fine, the issue is: I can not import the package.
(.venv) fabiobatalha:~/Work/crossrefapi$ poetry installInstalling dependencies from lock fileNo dependencies to install or updateInstalling the current project: crossrefapi (1.6.0)(.venv) fabiobatalha:~/Work/crossrefapi$ pythonPython 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import crossrefTraceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/fabiobatalha/Work/crossrefapi/src/crossref/__init__.py", line 3, in <module> VERSION = pkg_resources.get_distribution("crossref").version File "/home/fabiobatalha/Work/crossrefapi/.venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 478, in get_distribution dist = get_provider(dist) File "/home/fabiobatalha/Work/crossrefapi/.venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 354, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "/home/fabiobatalha/Work/crossrefapi/.venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 909, in require needed = self.resolve(parse_requirements(requirements)) File "/home/fabiobatalha/Work/crossrefapi/.venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 795, in resolve raise DistributionNotFound(req, requirers)pkg_resources.DistributionNotFound: The 'crossref' distribution was not found and is required by the application>>>
VERSION = pkg_resources.get_distribution("crossref").version
Your distribution is still crossrefapi, even if it contains a package crossref. That's one of the reasons, why the distribution name shouldn't differ from the actual package name.
Activity
GenosW commentedon Jun 1, 2022
Hey, I think what you want to use is:
packages = [{ from = "src", include = "crossref" }]fabiobatalha commentedon Jun 1, 2022
Hi @GenosW
Even with this configuration, it still not works, but now with a different error.
GenosW commentedon Jun 1, 2022
What are you trying to do? Which command are you invoking? --> There is some context missing to effectively help you.
Did
poetry installwork and are you able to import your package now in that env?Note: I'm not a poetry developer, just an avid user.
fabiobatalha commentedon Jun 1, 2022
for now I'm just trying to import the installed package.
Yes poetry install works fine, the issue is: I can not import the package.
abn commentedon Jun 1, 2022
@fabiobatalha recreate your virtualenv.
rm -rf .venv; poetry install.fabiobatalha commentedon Jun 1, 2022
Not even with a new virtualenv.
abn commentedon Jun 1, 2022
You should try using
importlib.metadatainstead ofpkg_resources. You can see here for an example.That said I suspect the issue was fixed in #5703. You can try using the version of poetry from master.
You can workaround this issue by moving the version discovery into it's own module rather than
__init__.py.finswimmer commentedon Jun 1, 2022
Your distribution is still
crossrefapi, even if it contains a packagecrossref. That's one of the reasons, why the distribution name shouldn't differ from the actual package name.abn commentedon Jun 1, 2022
oh yeah; @finswimmer is right - missed that.
Just change this.
fabiobatalha commentedon Jun 1, 2022
thanks @abn and @GenosW it works with importlib.metadata. The error was in the package name while trying to retrieve the package version.
It works also with pkg_resources.
github-actions commentedon Mar 2, 2024
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.