Error when calling Python ecCodes module from Matlab - python

I am trying to run a Python function from Matlab, but I get an error due to a missing library (the ecCodes library).
I tried to check the missing library by simply importing the module in Matlab:
>> py.importlib.import_module('eccodes')
Error using bindings><module> (line 35)
Python Error: RuntimeError: Cannot find the ecCodes library
However, I am perfectly able to import the module directly in Python through the Spyder IDE, as well as other Python modules from Matlab.
Furthermore, the ecCodes module should be in the Matlab search path, as it is located in:
C:\Users\username\AppData\Local\Continuum\anaconda3\Lib\site-packages\eccodes
Calling:
>> py.sys.path
in Matlab shows that the parent-folder is in fact included:
C:\Users\username\AppData\Local\Continuum\anaconda3\Lib\site-packages
Has anyone faced similar issues when calling Python from Matlab?
Thank you in advance!

Related

Python gives error when importing simple C extension module

On windows I have built a very simple "hello world" C extension (the file hello.c from this site https://gist.github.com/physacco/2e1b52415f3a964ad2a542a99bebed8f). Using VS2015 I successfully obtain hello.dll. The problem is that I can't figure out how to import this file/module.
In the python shell (python 3.7) I have made sure that I'm in the same folder as the hello.dll. I have also made sure that sys.path() contains the folder path. But when I write "import hello" I get an error "ModuleNotFoundError: No module named 'hello'"
Does anyone has an idea of what is wrong is this very simple setup?
Update:
When trying to import a module that does not exist the ModuleNotFoundError is reported. After renaming the hello.dll to hello.pyd an ImportError is returned. So it seems like it tries to actually load the module.
Python compiled modules on Windows have the extension .pyd, not .dll. If you'd built it using setup.py the file would be built with the correct name. However, you built it yourself and gave it a name that Python doesn't recognise as a module.
In terms of the build command: you have to link it with libpython. You don't look to be doing this. The error you report is definitely one that you can get if the module is not linked against all its dependencies.
I know you don't want to use setup.py, however I'd use it at least once just to see what it does and if it works. You'll then at least have a command that you can copy with a working set of options.

Importing winappdbg gives ModuleNotFoundError for breakpoint in PyCharm?

Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.

Blender opencv-python dllLoadError

I'm using Blender 2.78 (64bit) with Python 3.5.2 on Windows 7 (64bit). My situation is that I want to use opencv in combination with python in Blender. I went in serious trouble trying so and was working for days without any obvious success..
However from googling I found that there is a way to install pip as a module for blenders python and with pip I was able to install modules such as numpy oder scipy. This indeed also worked with opencv as it got successfully installed (including positive checks). It looked fine. But as I tried to import cv2 in a Console in Blender I got the error like the thread starter above:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.78\python\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I then tried to start blender python in an external shell and retried the import process resulting in the same error.
Next was retrying the complete procedure for my system python (same version 3.5.2) and everything worked perfectly.
From now on I was a bit confused as "pypi.python.org/pypi/opencv-python" towards opencv-python states that everything is linked statically and everything you have to do is what I have done. Looking in the FAQ the error is mentioned. You get the advise to check visual c++ redistributable and c runtime library. I did so, however, both is up to date and on system python opencv works perfectly that way.
Next try. As the system python works perfectly with opencv I removed blender python and pasted a copy of the system python instead. According to "blender.stackexchange.com/questions/5287/using-3rd-party-python-modules"
this is an alternative from using blenders own python.
Numpy, Scipy imports work perfectly. Importing cv2 leads to the same error as before.
If I now start the system-python copy that now is blenders python from a command shell cv2 can be imported.
Where is the difference here in the environment blender creates and the one from the shell??
I have installed a tool named listDlls to list all the dlls loaded by specific processes in order to compare blender-python and python. You can see some differences but I dont understand the matter of those except from the absence of the cv2 pyd in blenders python.
Any ideas?
First list is the python-process list, second the blender list:
https://ufile.io/uidy1
https://ufile.io/1eshi

Python module "preprocess" - does that exist?

In my python code I want to use a module called "topicmodels" (that can be found here https://github.com/sekhansen/text-mining-tutorial). The problem with this module is that whenever I want to "import topicmodels" in my Python code, I get the error message:
ImportError: No module name preprocess, more specifically in that topicmodels module is a Python file init.py that contains the line " from preprocess import * ". I googled and did not find a python module called preprocess - can anybody help me out on this?
(I am using Kubuntu and Python 3.5.2 | Anaconda 4.2.0).
Thanks a lot for any help!
This code is written for Python 2. You're on Python 3. The failing import is an implicit relative import, which Python 3 prohibits.
Run it on Python 2.
pip install preprocessing
Reference: https://pypi.org/project/preprocessing/

import Error while importing python nltk module in node.js using "python-node" module

I am trying to import python natural language processing toolkit nltk in node.js using node-python mentioned here: https://npmjs.org/package/node-python
The commands i am giving are similar as mentioned on the npm module site:
var python = require('node-python');
var os = python.import('os');
i am getting the following error:
Error: /usr/lib/python2.7/lib-dynload/datetime.so: undefined symbol: PyExc_SystemError
at repl:1:25
at REPLServer.self.eval (repl.js:109:21)
at rli.on.self.bufferedCmd (repl.js:258:20)
at REPLServer.self.eval (repl.js:116:5)
at Interface.<anonymous> (repl.js:248:12)
at Interface.EventEmitter.emit (events.js:96:17)
at Interface._onLine (readline.js:200:10)
at Interface._line (readline.js:518:8)
at Interface._ttyWrite (readline.js:736:14)
at ReadStream.onkeypress (readline.js:97:10)
I am using python2.7.2
After much search i found that this is a known bug in python2.7 and found a similar problem when importing from C here is the what i found:
similar error found while importing python datetime module from C
The problem seems to be in the datetime.so module, i was thinking of getting the updated version of the datetime module and compiling it separately to make it work. I am still looking for that module and comple instructions. I would really appreciate If anyone has a better suggestion to resolve this or even help me locate the place to find this datetime module and its compile instructions. I really don't want to compile the whole python to make it work.

Categories