Skip to content

Commit 9af16cf

Browse files
committed
Fix Windows: Properly load NEURON DLLs using os.add_dll_directory
- Use os.add_dll_directory() to add NEURON bin to DLL search path - Installation proceeds even if NEURON import fails - CSV files and package data install successfully regardless - Better error messages with NEURON paths for debugging - Bump version to 0.6.11
1 parent fc40c71 commit 9af16cf

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.6.11] - 2025-12-16
11+
12+
### Fixed
13+
- **Windows Installation**: Improved NEURON DLL loading during installation
14+
- Uses `os.add_dll_directory()` to properly add NEURON bin to DLL search path
15+
- Installation proceeds even if NEURON DLLs can't be loaded
16+
- CSV files and package data get installed successfully regardless
17+
- NEURON mechanisms can be compiled later after fixing NEURON setup
18+
- Better error messages showing NEURON paths for debugging
19+
1020
## [0.6.10] - 2025-12-16
1121

1222
### Fixed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "MyoGen"
3-
version = "0.6.10"
3+
version = "0.6.11"
44
description = "Modular and extensible neuromuscular simulation framework for generating physiologically grounded motor-unit activity, muscle force, and EMG signals (surface and intramuscular)"
55
readme = "README.md"
66
requires-python = ">=3.12"

setup.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,7 @@ def compile_nmodl(self):
6868

6969
def _compile_nmodl_windows(self, nmodl_path):
7070
"""Compile NMODL on Windows."""
71-
# First, verify NEURON can be imported (checks DLLs are accessible)
72-
try:
73-
import neuron
74-
from neuron import h
75-
except ImportError as e:
76-
raise ImportError(
77-
"\n" + "="*70 + "\n"
78-
"NEURON import failed - DLL not found\n"
79-
"="*70 + "\n\n"
80-
"NEURON is installed but cannot load DLLs.\n\n"
81-
"Please add NEURON's bin directory to your PATH:\n"
82-
"1. Search for 'Environment Variables' in Windows\n"
83-
"2. Edit 'Path' in System Variables\n"
84-
"3. Add: C:\\nrn\\bin (or your NEURON install location)\n"
85-
"4. Restart your terminal/IDE\n"
86-
"5. Retry: pip install myogen\n\n"
87-
f"Original error: {e}\n"
88-
"="*70 + "\n"
89-
) from e
90-
91-
# Try to find NEURON installation
71+
# Try to find NEURON installation first
9272
neuron_homes = [
9373
Path(os.environ.get("NEURONHOME", "")),
9474
Path("C:/nrn"),
@@ -97,14 +77,49 @@ def _compile_nmodl_windows(self, nmodl_path):
9777

9878
neuron_home = None
9979
for home in neuron_homes:
100-
if home.exists() and (home / "bin" / "mknrndll.bat").exists():
80+
if home.exists():
10181
neuron_home = home
10282
break
10383

10484
if not neuron_home:
105-
raise FileNotFoundError("mknrndll.bat not found - NEURON may not be installed")
106-
85+
print("\nWARNING: NEURON installation directory not found")
86+
print("Installation will continue without compiling NEURON mechanisms")
87+
return
88+
89+
# Add NEURON's bin directory to DLL search path (Python 3.8+)
90+
neuron_bin = neuron_home / "bin"
91+
if neuron_bin.exists():
92+
try:
93+
# This is the proper way to add DLL directories on Windows
94+
os.add_dll_directory(str(neuron_bin))
95+
print(f"Added NEURON DLL directory: {neuron_bin}")
96+
except (AttributeError, OSError) as e:
97+
print(f"Could not add DLL directory: {e}")
98+
99+
# Now try to import NEURON
100+
try:
101+
import neuron
102+
from neuron import h
103+
print("NEURON imported successfully")
104+
except ImportError as e:
105+
print("\n" + "="*70)
106+
print("WARNING: NEURON import failed")
107+
print("="*70)
108+
print(f"\nError: {e}")
109+
print(f"NEURON home: {neuron_home}")
110+
print(f"NEURON bin: {neuron_bin}")
111+
print("\nInstallation will continue without compiling NEURON mechanisms")
112+
print("You can compile them later by running:")
113+
print(" python -c \"from myogen import _setup_myogen; _setup_myogen()\"")
114+
print("="*70 + "\n")
115+
return
116+
117+
# Verify mknrndll.bat exists
107118
mknrndll_path = neuron_home / "bin" / "mknrndll.bat"
119+
if not mknrndll_path.exists():
120+
print(f"\nWARNING: mknrndll.bat not found at {mknrndll_path}")
121+
print("Installation will continue without compiling NEURON mechanisms")
122+
return
108123

109124
# Set up environment with NEURON paths
110125
env = os.environ.copy()

0 commit comments

Comments
 (0)