The same import code runs fine on Linux, but reports an error on Win
Hi,
With CIL 24.1.0, I tried to import
from cil.framework import AcquisitionData, AcquisitionGeometry, ImageData from cil.processors import TransmissionAbsorptionConverter from cil.recon import FBP, FDK from cil.plugins.astra.processors import FBP from cil.utilities.display import show_geometry from cil.plugins.astra.processors.FDK_Flexible import FDK_Flexible
This is fine for Linux, but I got this error message on Windows.
if '/' in name or '\' in name: ^^^^^^^^^^^ TypeError: argument of type 'NoneType' is not iterable
This looks like a problem interpreting the path? Do you know how to fix it? Thank you.
Hi @evenrose
could you please share the whole error stack? It seems it's complaining that name is None, but we cannot see where it comes from.
Thanks
Hi @evenrose
could you please share the whole error stack? It seems it's complaining that
nameisNone, but we cannot see where it comes from.Thanks
Of course.
It's not just for cil.framework, but for calling every other sub-package.
@evenrose, please could you try running this code snippet and paste the output? I suspect it's not finding a CIL library it needs, conda should take care of the paths but something may have gone wrong.
from ctypes.util import find_library
import ctypes
lib = "cilacc.dll"
lib_path = find_library(lib)
if lib_path is None:
print(f"Could not find the main DLL file: {lib}")
else:
print(f"Main DLL found: {lib_path}")
try:
proj_lib = ctypes.cdll.LoadLibrary(lib)
print("Main DLL loaded successfully.")
except OSError as e:
print(f"Could not load the main DLL file. Check dependencies: {e}")
@evenrose, please could you try running this code snippet and paste the output? I suspect it's not finding a CIL library it needs, conda should take care of the paths but something may have gone wrong.
from ctypes.util import find_library import ctypes lib = "cilacc.dll" lib_path = find_library(lib) if lib_path is None: print(f"Could not find the main DLL file: {lib}") else: print(f"Main DLL found: {lib_path}") try: proj_lib = ctypes.cdll.LoadLibrary(lib) print("Main DLL loaded successfully.") except OSError as e: print(f"Could not load the main DLL file. Check dependencies: {e}")
It returns:
Could not find the main DLL file: cilacc.dll Main DLL loaded successfully.
I tried to install CIL with and without additional packages. But the results are the same.
Did you activate the conda environment where you installed CIL, before running @gfardell 's code?
@evenrose @paskino I'm assuming the environment is activated as ctypes.cdll can load the library, it's just find_library that's failing. This suggests the application can find it, just not the search paths hard coded in to find_library which we are using here.
It is worth trying to load cil in a terminal rather than via an IDE to see if it's some behaviour of the IDE. But assuming you do still have the issue, could you test a fix for us? If you're not confident we could have a quick video call.
Basically I want to edit the file that's loading the library. This is a cil file inside the conda environment, so editing it will directly affect your install. But you can always recreate the environment and get back to where you were.
You'll need to know where your conda environment is saved. You can find this by opening your conda command prompt, activating the environment i.e. conda activate cil and then typing echo %CONDA_PREFIX%.
Once we have that we want to edit the file at:
%CONDA_PREFIX%\Lib\site-packages\cil\framework\CIL\Wrappers\Python\cil\framework\framework.py
We want to replace lines (ln 35-37):
elif platform.system() == 'Windows':
dll_file = 'cilacc.dll'
dll = util.find_library(dll_file)
with:
elif platform.system() == 'Windows':
dll = 'cilacc.dll'
Once that is done, activate your environment, launch python ands try to import things again.
Did you activate the conda environment where you installed CIL, before running @gfardell 's code?
Yes.
@evenrose @paskino I'm assuming the environment is activated as
ctypes.cdllcan load the library, it's justfind_librarythat's failing. This suggests the application can find it, just not the search paths hard coded in tofind_librarywhich we are using here.It is worth trying to load cil in a terminal rather than via an IDE to see if it's some behaviour of the IDE. But assuming you do still have the issue, could you test a fix for us? If you're not confident we could have a quick video call.
Basically I want to edit the file that's loading the library. This is a cil file inside the conda environment, so editing it will directly affect your install. But you can always recreate the environment and get back to where you were.
You'll need to know where your conda environment is saved. You can find this by opening your conda command prompt, activating the environment i.e.
conda activate ciland then typingecho %CONDA_PREFIX%.Once we have that we want to edit the file at:
%CONDA_PREFIX%\Lib\site-packages\cil\framework\CIL\Wrappers\Python\cil\framework\framework.pyWe want to replace lines (ln 35-37):
elif platform.system() == 'Windows': dll_file = 'cilacc.dll' dll = util.find_library(dll_file)with:
elif platform.system() == 'Windows': dll = 'cilacc.dll'Once that is done, activate your environment, launch python ands try to import things again.
Unexpected, it works fine when I use the terminal directly. My IDE is pycharm pro 2024.2.3.
I tried modifying the file as you said, but it seems that the error still appears in the IDE.
@evenrose @paskino I'm assuming the environment is activated as
ctypes.cdllcan load the library, it's justfind_librarythat's failing. This suggests the application can find it, just not the search paths hard coded in tofind_librarywhich we are using here.It is worth trying to load cil in a terminal rather than via an IDE to see if it's some behaviour of the IDE. But assuming you do still have the issue, could you test a fix for us? If you're not confident we could have a quick video call.
Basically I want to edit the file that's loading the library. This is a cil file inside the conda environment, so editing it will directly affect your install. But you can always recreate the environment and get back to where you were.
You'll need to know where your conda environment is saved. You can find this by opening your conda command prompt, activating the environment i.e.
conda activate ciland then typingecho %CONDA_PREFIX%.Once we have that we want to edit the file at:
%CONDA_PREFIX%\Lib\site-packages\cil\framework\CIL\Wrappers\Python\cil\framework\framework.pyWe want to replace lines (ln 35-37):
elif platform.system() == 'Windows': dll_file = 'cilacc.dll' dll = util.find_library(dll_file)with:
elif platform.system() == 'Windows': dll = 'cilacc.dll'Once that is done, activate your environment, launch python ands try to import things again.
Hi,
I also tried to modify the files which have similar error reports. Now the core of CIL can work fine. But there are other errors about plugins.
This is due to the installation path of the conda environment. Under Windows 11, if conda is not installed in the default path with full read and write permissions, env will be installed in the default user folder. Although the specific path is not clear, manually giving the folder full read and write permissions and reinstalling the environment can solve this problem.