Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency on Numpy not declared in setup.py #36

Open
nluetts opened this issue Jul 15, 2022 · 1 comment
Open

Dependency on Numpy not declared in setup.py #36

nluetts opened this issue Jul 15, 2022 · 1 comment

Comments

@nluetts
Copy link

nluetts commented Jul 15, 2022

Hi,

thanks for developing HAPI 😄

I just tried to install HAPI into a new virtual environment and it failed with the message:

ModuleNotFoundError: No module named 'numpy'

This is because Numpy is not declared in setup.py as a dependency.
You can use the install_requires keyword argument to include Numpy as an explicit dependency:

setup(
    name='hitran-api',
    version=HAPI_VERSION,
    packages=['hapi',],
    install_requires=["numpy",], # This is missing. Better specify a version, e.g. "numpy>=1.20" or whatever HAPI needs
    license='MIT',
)

The next problem is that setup.py imports HAPI_VERSION and HAPI_HISTORY form hapi.hapi.
This leads to setup.py trying to import Numpy, which then fails, although Numpy is now a declared dependency.
I solved this problem by moving the declarations of HAPI_VERSION and HAPI_HISTORY into a file _version.py in the root of the repository and then did

from _version import HAPI_VERSION, HAPI_HISTORY

in setup.py.

If you want to keep these declarations inside the hapi folder, I guess you would need to remove

from .hapi import *

from __init__.py, because this triggers the import of Numpy.

You should be able to do this if you instead declare the exported functions with the __all__ variable, like described here:
https://docs.python.org/3/tutorial/modules.html#importing-from-a-package

This problem seemed to be undetected for quite a while, I guess because most people have Numpy installed.
However, if your want to use a dedicated environment for your project (like I always do), Numpy will not be available by default.

Best regards
Nils

@nluetts
Copy link
Author

nluetts commented Jul 15, 2022

Oh, moving HAPI_VERSION and HAPI_HISTORY into the root folder does not work, because it is needed in the hapi module itself. The dirty and not well maintainable hack would be to just have a copy of _version.py in the hapi folder, but I guess using __all__ is the better solution. You seem to have used __all__ previously, it is commented out in __init__.py. Was there a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant