Skip to content

Commit 1fcab7a

Browse files
JujuDelJulien Delclos
andauthored
r5.0.4 (#255)
Co-authored-by: Julien Delclos <[email protected]>
1 parent 49b2c83 commit 1fcab7a

File tree

4 files changed

+59
-30
lines changed

4 files changed

+59
-30
lines changed

src/README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,34 @@
66

77
### Prerequisites
88

9+
Please check your python version with the following command. The result should be 3.8 or higher.
10+
11+
```
12+
python --version
13+
```
14+
915
- [ZED SDK 5.0](https://www.stereolabs.com/developers/) and its dependency [CUDA](https://developer.nvidia.com/cuda-downloads)
1016
- Python 3.8+ x64
1117
- C++ compiler
12-
- [Cython >= 3.0.0](http://cython.org/#download)
13-
- [Numpy >= 2.0](https://numpy.org/install/)
1418
- CuPy (optional)
1519

1620
The ZED SDK 4.X compatible API can be found in the [zedsdk_4.X branch](https://github.com/stereolabs/zed-python-api/tree/zedsdk_4.X).
1721

18-
Please check your python version with the following command. The result should be 3.8 or higher.
22+
**Python Dependencies:**
23+
- Use `requirements.txt` for Python 3.9+ with modern dependencies
24+
- Use `requirements_legacy.txt` for older Python versions or legacy setups
1925

20-
```
21-
python --version
22-
```
26+
Install dependencies with:
27+
```bash
28+
# For modern Python environments (recommended)
29+
pip install -r requirements.txt
2330

24-
Cython and Numpy can be installed via pip.
25-
```
26-
python -m pip install cython numpy
31+
# For legacy Python environments
32+
pip install -r requirements_legacy.txt
2733
```
2834

2935
**Note:** On Linux, it is advised to use the `python3` command instead of `python` which by default point to python 2.7. To do so, the following packages `python3-dev` and `python3-pip` need to be installed.
3036

31-
```
32-
python3 --version
33-
pip3 install -r requirements.txt
34-
```
35-
3637
### Build the plugin
3738

3839
```

src/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cython >= 3.0.0
2-
numpy >= 2.0
2+
numpy >= 2.0, < 3.0.0
33
wheel
4+
setuptools

src/requirements_legacy.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cython >= 3.0.0
2+
numpy >= 1.13, < 2.0
3+
wheel
4+
setuptools

src/setup.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,45 @@
2626
import sys
2727
import shutil
2828
import re
29-
# import numpy # Import moved to after setup_requires might install it
29+
import numpy as np
3030

3131
from setuptools import setup, Extension
32-
from Cython.Build import cythonize
33-
34-
# It's good practice to try importing numpy after setup_requires had a chance
35-
# However, numpy.get_include() is needed early for incDirs.
36-
# oldest-supported-numpy will ensure a suitable version is available for the build.
37-
import numpy
3832

33+
# Import Cython being careful with capitalization for non-modern Python environments
34+
try:
35+
from Cython.Build import cythonize
36+
except ModuleNotFoundError as e:
37+
if not sys.platform.startswith('win'):
38+
raise ModuleNotFoundError(e)
39+
40+
# This is a workaround for Cython installation issues on Windows
41+
# where the package is installed as 'cython' but internal imports expect 'Cython'
42+
import sys
43+
try:
44+
import cython
45+
# Add the cython module as 'Cython' in sys.modules so internal imports work
46+
sys.modules['Cython'] = cython
47+
48+
# Also need to map the submodules
49+
import cython.Build
50+
import cython.Compiler
51+
sys.modules['Cython.Build'] = cython.Build
52+
sys.modules['Cython.Compiler'] = cython.Compiler
53+
54+
# Import all submodules that are needed
55+
for attr_name in dir(cython):
56+
attr = getattr(cython, attr_name)
57+
if hasattr(attr, '__name__') and attr.__name__.startswith('cython.'):
58+
capitalized_name = attr.__name__.replace('cython.', 'Cython.')
59+
sys.modules[capitalized_name] = attr
60+
61+
# Now try the import again
62+
from Cython.Build import cythonize
63+
print("Successfully imported cythonize using workaround")
64+
65+
except (ImportError, ModuleNotFoundError, AttributeError) as e:
66+
print(f"Cython import failed: {e}")
67+
raise ImportError("Cython is not installed or not properly configured. Please install Cython to proceed.")
3968

4069
incDirs = ""
4170
libDirs = ""
@@ -110,12 +139,6 @@ def clean_cpp():
110139
shutil.rmtree("build")
111140
sys.exit()
112141

113-
# numpy.get_include() will be called here.
114-
# If oldest-supported-numpy is in setup_requires,
115-
# setuptools attempts to install it before this script fully runs,
116-
# making the 'oldest' numpy available for get_include().
117-
numpy_include_dir = numpy.get_include()
118-
119142
if sys.platform == "win32":
120143
if os.getenv("ZED_SDK_ROOT_DIR") is None:
121144
print("Error: ZED_SDK_ROOT_DIR is not set. You must install the ZED SDK and set this environment variable.")
@@ -125,7 +148,7 @@ def clean_cpp():
125148
sys.exit(1)
126149
else:
127150
check_zed_sdk_version(os.getenv("ZED_SDK_ROOT_DIR")+"/include")
128-
incDirs = [numpy_include_dir, os.getenv("ZED_SDK_ROOT_DIR")+"/include",
151+
incDirs = [np.get_include(), os.getenv("ZED_SDK_ROOT_DIR")+"/include",
129152
os.getenv("CUDA_PATH") + "/include"]
130153

131154
libDirs = [os.getenv("ZED_SDK_ROOT_DIR")+"/lib",
@@ -142,7 +165,7 @@ def clean_cpp():
142165
sys.exit(1)
143166
else:
144167
check_zed_sdk_version(zed_path+"/include")
145-
incDirs = [numpy_include_dir,
168+
incDirs = [np.get_include(),
146169
zed_path + "/include",
147170
cuda_path + "/include"]
148171

0 commit comments

Comments
 (0)