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.
Related
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.
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.
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/
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!
I have downloaded an unix executable 'gtselect' used for analysing scientific data. This comes as part of a larger package of tools with installation instructions such that 'gtselect' can be called from the current working directory.
When I just run 'gtselect' everything works as expected.
I then use a python script 'gt_apps.py' which uses GtApp to wrap the tools as python objects
from GtApp import GtApp
filter = GtApp('gtselect')
and then use a different script 'run.py' to call gtselect as a python object and run it:
import gt_apps
gt_apps.filter.run()
When I run this, I receive the error
dyld: Library not loaded: libdataSubselector.dylib
Referenced from: path/bin/gtselect
Reason: image not found
Now, the library it is trying to load is instead found at
path/lib/libdataSubselector.dylib
I have tried setting
export DYLD_LIBRARY_PATH = path/lib/
but the same error persists.
Any advice? Thanks