lubianat / pyorcidator

MIT License
9 stars 5 forks source link

ModuleNotFoundError: No module named 'pyorcidator' #13

Closed lubianat closed 2 years ago

lubianat commented 2 years ago

@cthoyt I tried to install pyorcidator as a package by running pip3 install . in a virtual env. When I try to call the function, it gives the following error:

Traceback (most recent call last):
  File "/home/lubianat/Documents/main_venv/bin/pyorcidator", line 5, in <module>
    from pyorcidator.cli import cli
ModuleNotFoundError: No module named 'pyorcidator'

it is installed, though, as it is in /home/lubianat/Documents/main_venv/bin/pyorcidator, do you know what might be happening?

lubianat commented 2 years ago

Update: that only happens if I run pip install ., pip install -e . works just fine.

jvfe commented 2 years ago

I believe I found out what I believe to be the issue here. My knowledge in this regard is not the best, so maybe someone else can explain it better. But, nevertheless:

Python usually requires __init__.py files in every directory of the package, so the package's code can be bound to its namespace - essentially so python can recognize these directories as containing the package's code, not just random scripts. If these files are not found, pip installs a package called 'pyorcidator' but can't find the functions it calls - hence the ModuleNotFound error.

So a simple solution would be to add empty __init__.py files to src/pyorcidator/ and src/pyorcidator/dictionaries/ - that fixes the issue at hand.

Now as for the reason as to why this doesn't happen in pip install editable's mode is still a bit unclear to me, but I believe the reason to be related to the fact that editable mode (which calls python's setuptools develop command) doesn't actually install the package, instead it creates a symlink to the current directory in order to 'watch' for changes.

cthoyt commented 2 years ago

Really insightful, @jvfe. I have been using my cookiecutter for so long that I forgot the consequence of not having __init__.py. I think if you do from pyorcidator import import_info, this should work without any changes, since this is an actual python module and not a "virtual" one