issues with VTK's Python bindings - python

First of all, I did successfully compile and install VTK, as it can be seen from the following message
Installed /tmp/yifli/lib/python2.6/site-packages/VTK-5.8.0-py2.6.egg
However , when I try to import vtk, I got the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/yifli/lib/python2.6/site-packages/VTK-5.8.0-py2.6.egg/vtk/__init__.py", line 124, in <module>
__helper.refine_import_err('qvtk', 'vtkQtPython', exc)
File "/tmp/yifli/lib/python2.6/site-packages/VTK-5.8.0-py2.6.egg/vtk/__helper.py", line 32, in refine_import_err
raise LinkError, str(exc)
vtk.__helper.LinkError: /tmp/yifli/lib/vtk-5.8/libQVTK.so.5.8: undefined symbol: _ZN19QAbstractProxyModel11setItemDataERK11QModelIndexRK4QMapIi8QVariantE
And all the tests failed when I run 'ctest -R Python' in the building directory.
Any help is highly appreciated.

This looks like you built with Qt support, QVTK is the Qt widget(s) to support VTK render window. You have an issue with an undefined symbol from Qt (QAbstractProxyModel), likely due to compiling with a newer Qt than that available when you import the VTK python module. Running,
ldd /tmp/yifli/lib/vtk-5.8/libQVTK.so.5.8
would show you which Qt library it is trying to link to.

Related

Python do not work when executed from Java on M1 Mac

I have a bash script that runs a python script:
#!/bin/bash
restest-env/bin/python3 script.py $1 $2 $3
When executed from terminal, everything works fine. Instead, when executed from a Java application with:
ProcessBuilder pb = new ProcessBuilder(command, String.join(" ",commandArgs));
Process proc = pb.start();
proc.getOutputStream();
String stdout = IOUtils.toString(proc.getInputStream(), Charset.defaultCharset());
String stderr = IOUtils.toString(proc.getErrorStream(), Charset.defaultCharset());
proc.waitFor();
I get this M1 chip-related error:
Traceback (most recent call last):
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ml/python-scripts/al_predictor.py", line 2, in <module>
import numpy as np
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/bin/python3"
* The NumPy version is: "1.23.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
2022-07-18 11:21:14 INFO stdout:36 - Traceback (most recent call last):
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ml/python-scripts/al_predictor.py", line 2, in <module>
import numpy as np
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/bin/python3"
* The NumPy version is: "1.23.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/giulianomirabella/Desktop/RESTest/ml/restest-env/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
So the strange thing is that python works fine while executed directly from terminal, but fails when executed from Java. I can not use conda. Any ideas?
I had the same issue where I was trying to use Java ProcessBuilder to run a terminal command to run a python project.
My command ran fine in the terminal but was not working when run from the Java program. When running command 'uname -p' I could see when the terminal was open manually I got 'arm' but when Java ran it it was 'x86_64 i386'. Basically java was running as an x86_64 process but my python install was arm so it failed.
To solve the issue I simply installed java jdk 18.0.2 and run my java program using this jdk. It worked after this

Python can't load libc when importing xfsm module

I'm trying to write Python code to manipulate Xerox FST files, and I've installed the Python bindings for libxfsm and the XFSM library available through http://fsmbook.com. I'm running 64-bit Ubuntu. The installation goes fine, but when I try to import the xfsm module, I get this error:
>>> import xfsm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/xfsm/__init__.py", line
30, in <module>
import xfsm.errors # So error handler gets installed
File "/usr/local/lib/python2.7/dist-packages/xfsm/errors.py", line
8, in <module>
from xfsm.utils import *
File "/usr/local/lib/python2.7/dist-packages/xfsm/utils.py", line
39, in <module>
libc = cfsm.load_library("c")
File "/usr/local/lib/python2.7/dist-packages/xfsm/cfsm_api.py", line
366, in l oad_library
raise ImportError("%s not found." % libname)
ImportError: c not found.
Inspecting the source code for the Python interface, it looks like it is trying and failing to find libc, and failing, but I am at a loss on how to fix that.
Has anybody else gotten the Python-XFST interface working, or have any idea what's going wrong and how to fix it?
I had same problem on 64-bit Ubuntu 14.04. The problem is it can't find libc. In my case libc on my OS is name libc.so.6(I don't know why, I am new on Ubuntu). But the Python-XFST doesn't recognize it (Detail your can refer to source file)
My solution is simple, just modify xfsm/utils.py file in
**Line 39** : libc = cfsm.load_library("c")
to
**Line 39** : libc = cfsm.load_library("libc.so.6")
Remember to add the path to libc.so.6 in env.

Importerror with Python Buffer Library

I downloaded this library: https://github.com/bufferapp/buffer-python
Ran the setup.py install, and then tried to run some code using the newly installed library.
What happens though is I get this error:
Traceback (most recent call last):
File "twitter-quote-bot.py", line 14, in <module>
from buffpy.managers.profiles import Profiles
ImportError: No module named managers.profiles
The only way I've found to fix it is to move my program (twitter-quote-bot) into the downloaded folder from Buffer and run it there.
Did I do something wrong in the installation? It seems like I should be able to do these imports globally.
Thanks in advance!

Python: multiple installations

I was successfully using python in my programs and importing necessary modules including MySQL. However, to get IDLE on my computer I downloaded a new copy of python. I'm really not sure what I did or what happened but when I try to run a program now that uses MySQL I get the following error:
Traceback (most recent call last):
File "MyFile.py", line 11, in <module>
import MySQLdb
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so
any ideas on how to fix this?
Actually I fixed the problem by reinstalling MySQLdb following the step found here. I'm not sure how well this will work for additional modules though

have trouble with PIL to create PhotoImage object

I have Python 2.6 running on Fedora 13. I installed PIL 1.1.7, and I get the successful installed message in the Python prompt. I am able to import PIL.PhotoImage,but when I try to run the following, I get an error.
mgobj = PhotoImage(file=imgpath)
Stacktrace:
Traceback (most recent call last):
File "viewer-tk.py", line 25, in <module>
imgobj = PhotoImage(file=imgpath) # now JPEGs work!
File "/home/Toshiba/vinpython/venv/lib/python2.6/site-packages/PIL/ImageTk.py", line 116, in __init__
self.paste(image)
File "/home/Toshiba/vinpython/venv/lib/python2.6/site-packages/PIL/ImageTk.py", line 181, in paste
import _imagingtk
ImportError: No module named _imagingtk
In the module ImageTk.py , I see _imagingtk being imported,but i am not sure how do it get that module.Help is greatly appreciated!!!
You need to install Tkinter python module as stated at this trac. But since it's an integral part of python distributions. Since you are using fedora take a look at this page where you can install Tkinter when it doesn't come along, even being for Fedora 3 I think it might help.

Categories