michalsta / opentims

Open-source C++ and Python module for opening binary timsTOF data files.
Other
41 stars 11 forks source link

import error #11

Closed cjhjhj closed 2 years ago

cjhjhj commented 2 years ago

Hello there,

I installed OpenTIMS using "pip install opentimspy", and "pip install opentims_bruker_bridge" in a Windows computer. The installation went well without problems. However, when I tried to use the package, I came across errors as follows,

>>> import opentimspy
Traceback (most recent call last):
  File "C:\...\Continuum\anaconda3\lib\site-packages\opentimspy\__init__.py", line 19, in <module>
    import libopentims_support
ModuleNotFoundError: No module named 'libopentims_support'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\...\Continuum\anaconda3\lib\site-packages\opentimspy\__init__.py", line 25, in <module>
    ctypes.CDLL(support_lib.get_filename(), ctypes.RTLD_GLOBAL)
AttributeError: 'NoneType' object has no attribute 'get_filename'

Visual studio 2019 and python 3.8 were used. Please let me know what the problem is. Thanks

jeriedel commented 2 years ago

Hi all,

I can confirm this problem and ran into the same exception on my Windows 10 machine using Python 3.9.6. The problem seems to arise from the fact, that libopentims_support is not build as an Extension on Windows machines, however the functionality of the libopentims_support library should be included in opentimspycpp. As a quick fix to the problem, I made the following changes to the \_init__.py file in the opentimspy folder.

try:
    import libopentims_support
    import opentimspy_cpp
except (ImportError, ModuleNotFoundError):
    import ctypes
    import pkgutil

    support_lib = pkgutil.get_loader("libopentims_support")

    if support_lib is not None:
        ctypes.CDLL(support_lib.get_filename(), ctypes.RTLD_GLOBAL)
        cpp_lib = pkgutil.get_loader("libopentims_cpp")
        ctypes.CDLL(cpp_lib.get_filename(), ctypes.RTLD_GLOBAL)

    import opentimspy_cpp

I use opentims in conjunction with timspy and data loading worked fine for me after the changes. However, the extent of the canges should be checked by the opentims team.

michalsta commented 2 years ago

Hi,

Just letting you know I'm working on it, I'm just not a Windows guy, so it might take a while while I stumble around ;)

The fix will probably be something along this lines, I just have to make sure it doesn't break everything on other platforms...

michalsta commented 2 years ago

Hi,

I've released a new version, hopefully fixing this issue. (v1.0.10)

michalsta commented 2 years ago

OK, closing. Feel free to reopen if you still have the same issue with v1.0.10.