@@ -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 ("\n WARNING: 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"\n Error: { e } " )
109+ print (f"NEURON home: { neuron_home } " )
110+ print (f"NEURON bin: { neuron_bin } " )
111+ print ("\n Installation 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"\n WARNING: 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