Skip to content

Commit

Permalink
maybe fix setup.py ModuleNotFoundError: No module named 'numpy'
Browse files Browse the repository at this point in the history
by lazy-importing numpy
  • Loading branch information
janosh committed Sep 11, 2024
1 parent 4f044eb commit 45a1fd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ find = { include = ["chgnet*"], exclude = ["tests", "tests*"] }
"chgnet.pretrained" = ["*", "**/*"]

[build-system]
requires = [
"Cython",
"setuptools>=65",
"wheel",
"numpy>=2.0.0",
]
requires = ["Cython", "numpy>=2", "setuptools>=65", "wheel"]
build-backend = "setuptools.build_meta"

[tool.ruff]
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from __future__ import annotations

import numpy as np
from setuptools import Extension, setup

ext_modules = [Extension("chgnet.graph.cygraph", ["chgnet/graph/cygraph.pyx"])]


def lazy_numpy_include() -> str:
"""Get the numpy include directory lazily."""
import numpy as np

return np.get_include()


setup(
ext_modules=ext_modules,
setup_requires=["Cython"],
include_dirs=[np.get_include()],
include_dirs=[lazy_numpy_include()],
)

0 comments on commit 45a1fd7

Please sign in to comment.