Error with compiling Python code that includes Rust written modules - python

So I have written an app that uses a bit of Rust code, and while using "auto-py-to-exe" to turn it into an executable, it gives this error when I run it:
ModuleNotFoundError: No module named 'data_clean'
(data_clean is my rust module)
I used maturin for converting rust -> python and I ran 'maturin develop' on it successfully, it works as expected within my IDE.
I included the folder with all of my Rust code in it, I'm not sure why it's giving me a tough time.

Related

Using custom cython modules in colab

I'm trying to run some code python code in Google colab. This code uses some custom modules I wrote, some of which were written in cython. On my local machine, I'd normally compile the cython code first before running my main python script. What is the correct way of doing this on colab, if there is one? Right now, the script throws an error when it tries to import my cython modules. Specifically, I get the error
ImportError: model/cython_library/core.so: invalid ELF header
which makes sense, since the core.so file was compiled on my local machine instead of gcloud.

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.

Embedding Python in a Qt Creator project

I'm working on a project that requires C++ to call a program written in Python that relies on Python exclusive modules.
The project is handled using Qt Creator, and Python 3.7.5 and its packages are installed via Miniconda. I've gotten a basic embedding working using Pybind11 where basic interfacing works, however, most external modules cannot be imported.
For example, when importing Numpy through Pybind11, the following error is thrown (reduced for brevity):
Importing the numpy c-extensions failed.
Original error was: /home/brentnallt/miniconda3/envs/car_class_nogpu/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-x86_64-linux-gnu.so: undefined symbol: PyMemoryView_FromObject
A similar error occurs when importing tensorflow through Pybind11:
ImportError: /home/brentnallt/miniconda3/envs/car_class_nogpu/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so: undefined symbol: PyUnicode_FromFormat
It appears to be a problem with Python's C API being found when reading C extension shared libraries. However, modules like lxml which use C source files import just fine. Additionally, I can import problem modules in projects separate from the project I'm working on, implying it's a setup problem. Note that this test project setup doesn't actually use any QT functionality, whereas the main one does.
My PYTHONHOME environment variable looks like:
['/home/brentnallt/miniconda3/envs/car_class_nogpu/lib/python3.7', '/home/brentnallt/miniconda3/envs/car_class_nogpu/lib/python3.7/site-packages', '/home/brentnallt/miniconda3/envs/car_class_nogpu/lib/python37.zip', '/home/brentnallt/miniconda3/envs/car_class_nogpu/lib/python3.7/lib-dynload', '.']
Are there any special considerations I have to make when embedding with Qt Creator? Or is this likely a different problem from a setup error?
Maybe you can consider using PythonQt as an alternative module for calling and importing python libraries from Qt application.
I've used it a lot in my projects and it never failed, but never used it with any kinda data scientific modules maybe you could give it a chance
https://mevislab.github.io/pythonqt/

Using Matlab compiler to compile a matlab script with some python module imported

I am trying to compile a matlab script using Matlab Application compiler. However, in the matlab script, I use a python object adb_object from adb_lib.py:
tmp = py.adb_lib.adb_object()
I've already added the adb_lib.py as well as 'C:\Python27\python.exe' with mcc -a, but when I run the compiled exe file, it's still said:
Undefined Variable "py" or class "py.adb_lib.adb_object".
Any idea about this? Thanks!

Python: ImportError from compiled source code

I'm having problems while running a compiled source code. The code itself is correct and if I run python file.py everything goes fine; if I compile it with pyinstaller or software like this, and then I run the compiled file it says ImportError: No module named _cffi_backend. But when I open python and import cffi and/or _cffi_backend python doesn't show error. Investigating in my code I found that the problem is just with padding from cryptography, so if I don't import padding the output doesn't show errors (obviously errors comes because the code doesn't work well without padding module).
Can someone help me?
I just ran into this issue as well.
What worked for me was adding in --hidden-import=_cffi_backend option when building with pyinstaller.

Categories