ratal / mdfreader

Read Measurement Data Format (MDF) versions 3.x and 4.x file formats in python
Other
169 stars 74 forks source link

dataRead: relative import fails #50

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello, calling the mdfreader.mdf on a sorted mdf4 file, I face the error:

Unexpected error: (<class 'SystemError'>, SystemError("Parent module '' not loaded, cannot perform relative import",), <traceback object at 0x000000000E4F4108>) dataRead crashed, back to python data reading

I am using python 3.52 with Anconda3 distribution on a 64bit Windows machine. I am running the mdfreader downloaded from github yesterday, 05.04.2017.

I tracked it down to come possibly from line 1180 in mdf4reader.py: from .dataRead import dataRead

Looking for this module on my system I found dataRead.cp35-win_amd64.pyd in Lib\site-packages.

Just to make sure, I updated cython to 0.25.2, checked that system path includes this folder, however the import of dataRead module keeps failing.

Any suggestions? I would appreciate that!

ratal commented 7 years ago

Hi, I think you need to recompile your dataRead with Cython. Most probably updating some libraries broke it or during install compilation failed for some reason I can not say without having more details. If you try to install again, it will try to compile again. Could you do ?: python setup.py develop (or install) ? And report the output.

ghost commented 7 years ago

Hello ratal, thank you for your very quick response. Here is what I did:

1) Just to make sure, I uninstalled cython and installed cython again via pip install cython (Successfully installed cython-0.25.2 ) 2) I called the setup.py from the mdfreader-master zip I downloaded from this page: python setup.py develop The output gives:

... WARNING: Extension name 'dataRead' does not match fully qualified name 'mdfreader.dataRead' of 'mdfreader/dataRead.pyx' Compiling 'mdfreader/dataRead.pyx' because it changed Cythonizing mdfreader/dataRead.pyx ... building 'dataRead' extension ... several warnings on different issues (numpy API deprecated, conversion from double to float, __int64 to long) but no errors ... c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /LIBPATH ... /EXPORT:PyInit_dataRead build\temp.win-amd64-3.5\Release\mdfreader/dataRead.obj /OUT:build\lib.win-amd64-3.5\dataRead.cp35-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.5\Release\mdfreader\dataRead.cp35-win_amd64.lib dataRead.obj: warning LNK4197: Export "PyInit_dataRead" wurde mehrmals angegeben; erste Angabe wird verwendet. Bibliothek "build\temp.win-amd64-3.5\Release\mdfreader\dataRead.cp35-win_amd64.lib" und Objekt "build\temp.win-amd64-3.5\Release\mdfreader\dataRead.cp35-win_amd64.exp" werden erstellt ... copying build\lib.win-amd64-3.5\dataRead.cp35-win_amd64.pyd -> ...

So, the only irritatiting thing is that linker warning on multiple "PyInit_dataRead" exports and that the first entry is taken. Besides that, there is no error message.

I then run my script importing the mdf4 again: the error is still raised.

ratal commented 7 years ago

Ok, dataRead seems to be compiling so you might encounter same issue as for #49 there is probably a relative path issue for the import. what happens if you do instead from mdfreader.dataRead import dataRead Anyway, it should not prevent you to read mdf4 files as normally python code of dataRead is existing, but it will be slower. I must admit the change I did to include absolute path instead of relative for imports of modules was rather unstable, depending of python version and I realise now also depending of platform (windows/linux). I might come back to previous way (0.2.3) of importing modules. Fell free to propose :)

ghost commented 7 years ago

Doesn't help neither. Anyhow, thanks for your help. If I find any solution I will post it.

ratal commented 7 years ago

Sorry but another try: from dataRead import dataRead without the dot before dataRead ? (in the end, the dot is not consitent with the import header of the file)

ghost commented 7 years ago

Well, this was the very first thing I tried :-)

ratal commented 7 years ago

I could reproduce this issue on a fresh windows10 + latest anaconda. I will investigate how to fix this and keep you informed.

maxtheaviator commented 7 years ago

Hello, I've been running exactly into the same error. Anaconda: 4.3.16 Python: 3.6 OS: Windows 7 64 bit

Unexpected error: (<class 'ImportError'>, ImportError("cannot import name 'dataRead'",), <traceback object at 0x0000000016BCED88>) dataRead crashed, back to python data

Played arround with import statements as suggested. No luck.

When I build setup.py following Warning is displayed in the console: Warning: Extension name 'dataRead' does not match fully qualified name 'mdfreade r.dataRead' of 'mdfreader/dataRead.pyx' Compiling mdfreader/dataRead.pyx because it changed. [1/1] Cythonizing mdfreader/dataRead.pyx

Do you have any suggestions yet to overcome this issue?

By the way, great project. Thx.

ratal commented 7 years ago

This warning seems to be related to the fact that dataRead is located in a module, not at the root. Putting dataRead one level up and adapting setup.py, warning disappears but problem remains: There is no generation of .pyd from the cythin generated C code. Apparently things have changed from python 3.5-6 about compilation of modules or extension in windows. I tried installing windows SDK but still issue. Continuing to investigate.

ratal commented 7 years ago

I could finally generate the dataRead.pyd if a compiler is properlly installed You need to follow below instructions: cython wiki If you use python 3.5-6 you need to install visual studio 2015 (ticking common Tools for visual studio) and then relaunch a python setup.py built_ext --inplace I am a bit sad that latest cython implementation (anaconda integration ?) remain "silent" if no compiler is installed, finally more complicated to troubleshoot. Maxtheaviator, do you have a compiler installed ? Smatti, I saw from your command line, you generate a pyd. cythonize seems to fail copying the pyd from the build directory to mdfreader folder (because it should be located to module root directory but then does not rename it, under investigation). Could you rename and move it to mdfreader/mdfreader, then check status ? Could you both check this is solving your issue ?

maxtheaviator commented 7 years ago

thank you. I had an compiler installed. mingw64. I've Read some documents on the web and installed Microsoft Visual Studio 2010 as I wasn't able to install 2015 due to lack of admin rights in our environment.

for python <= 3.4 you need the compiler of Visual Studio 2010

python >= 3.5 VS 2015

I've created a python 3.4 environment in anaconda and specified the compiler during building progress:

python setup.py built_ext --inplace -compiler=msvc #python 3.4 activated

you may have to set VS90COMNTOOLS environment variable accordingly.

then:

python setup.py install

now it works.


Maximilian Murauer

Friedenheimer Brücke 19 80639 München

Tel.: +49-89-18008089 Mobil: +49-151-15730055

E-Mail: max.murauer@gmail.com

Am 27.04.2017 um 23:04 schrieb Aymeric Rateau notifications@github.com:

I could finally generate the dataRead.pyd if a compiler is properlly installed You need to follow below instructions: cython wiki If you use python 3.5-6 you need to install visual studio 2015 (ticking common Tools for visual studio) and then relaunch a python setup.py built_ext --inplace I am a bit sad that latest cython implementation (anaconda integration ?) remain "silent" if no compiler is installed, finally more complicated to troubleshoot. Maxtheaviator, do you have a compiler installed ? Smatti, I saw from your command line, you generate a pyd. cythonize seems to fail copying the pyd from the build directory to mdfreader folder (because it should be located to module root directory but then does not rename it, under investigation). Could you rename and move it to mdfreader/mdfreader, then check status ? Could you both check this is solving your issue ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

ratal commented 7 years ago

Great Max, In latest commit, dataRead changed location and it seems to be solving this issue. Please confirm.

ratal commented 7 years ago

Long time no feedback, closed