Is there a way to load a fxml into jython logic code? - python

I need to attach a GUI to python application. I've seen tkinter and Qt5, but they make too native GUIs. In fact, using the first one I cannot customize my elements with css, and the second one only support a subset of it. That's why I wonder if I can use a fxml file to create a nice interface.
Then, I followed this link and tried to use jython. In one comment, they said: "you can manually add jfxrt.jar to your module search path if you are using a version of Java where it isn't available." This is my case, but I have no idea about how to do it. I downloaded the jfxrt.jar and I put it in the same python script folder, but the same error occurs when I try jython script.py:
WARNING: Illegal reflective access by jnr.posix.JavaLibCHelper$ReflectiveAccess (file:/usr/share/java/jnr-posix.jar) to method sun.nio.ch.SelChImpl.getFD()
WARNING: Please consider reporting this to the maintainers of jnr.posix.JavaLibCHelper$ReflectiveAccess
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Traceback (most recent call last):
File "./test.py", line 10, in <module>
from javafx.application import Application
ImportError: No module named javafx
What I executed is the code in the page previously linked. What can I do to solve this import error?

Related

How to find which DLL failed in "ImportError: DLL load failed while importing" in python?

Context
Are there commands to enhance the error message that is received such that python displays which .dll file it cannot find?
For error:
python test_cv2.py
Traceback (most recent call last):
File "test_cv2.py", line 1, in <module>
import cv2
File "E:\Anaconda3\envs\py38\lib\site-packages\cv2\__init__.py", line 5, in <module>
from .cv2 import *
ImportError: DLL load failed while importing cv2: The specified module could not be found.
(py38) E:\somepath>
I would like to determine which .dll file is actually not being found. To do so, I downloaded and run DependenciesGui.exe from this repository.. Next I fed the DependenciesGui.exe the cv2.cp38-win_amd64.pyd which indicates api-ms-win-core-wow64-l1-1-1.dll is missing, amongst others.
I currently do not have a way to verify that the .dll files that are reported missing by dependenciesGUI.exe are also the files that python 3.8 is not finding in the anaconda environment.
A way to implicitly verify that the python 3.8 missing .dll files are the same as the same files reported missing by dependenciesGUI.exe would be to download and paste all the missing .dll files into ../system32/. Followed by inspecting if the error message dissapears/changes. However one of the .dll files reported missing is: api-ms-win-core-wow64-l1-1-1.dll which I am not yet able to find (online). Also I tried to cheat to copy and rename api-ms-win-core-wow64-l1-1-0.dll to api-ms-win-core-wow64-l1-1-1.dll but that (luckily) doesn't enable the dpendenciesGUI.exe to recognize the .dll file as found.
Question
How can I make the error message/traceback of python explicitly mention which .dll file is (the first .dll file that is) not found?
Note
This is not about solving the xy-problem of installing opencv.
Short answer: No.
Although it is probably not completely impossible, it would require to bind a tool like dependenciesGUI in Python, in order to be able to call it in that given context (namely taking into account the actually search path for dll in Python and already loaded dynamics libraries). It would be quite a lot of work for little gain. Indeed, the default search path in Python>=3.8 on Windows should be very similar to the one of dependenciesGUI, so that the missing dll should be the same. Personally, I'm developing pre-compiled binary distributions for Python, and so far dependenciesGUI was enough to identify the missing libraries at Python import.

'module' object has no attribute 'utilities'

Trying to implement ytini (yt for Houdini) Python framework.
http://www.ytini.com/
Resolved most install erros but am still getting the following when I load a datfile
Not sure if this might be related to some configuration for ytini or if its more of a Python specific error.
Traceback (most recent call last): File "", line 14,
in File "/home/jim/.local/lib/python2.7/site-packages/yt/__init__.py", line 44,
in import yt.utilities.physical_constants as physical_constants
AttributeError: 'module' object has no attribute 'utilities
Can any Python experts suggest any troubleshooting steps?
Update>
If I simply do an import yt I get the following error
Warning! HDF5 library version mismatched error
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
'HDF5_DISABLE_VERSION_CHECK' environment variable is set to 1, application will
continue at your own risk.
Headers are 1.10.0, library is 1.8.11
This error means that you are treating yt.utilities as an object from which you are trying to access the object attribute physical constants, which is correct, but python thinks that this attribute doesn't exist. However, I am unable to reproduce this error and can access the values stored therein. What else is in your code? It looks like you are accessing another module function of yt which uses the constants attributes, is that correct? Also, are you using python 2.7 or 3.x?
In terms of installing package in 2 different places, I've had this happen before which was very frustrating, but the folders can be found by doing a folder search for the module name and should return all versions saved in different locations. The exact location of the modules varies with IDE, OS, weather...

Writing ImageJ Python scripts in PyCharm

I'm able to install Jython (via homebrew), configure PyCharm to use it as my interpreter, but I can't get PyCharm to import ij.
/usr/local/bin/jython -Dpython.path=/tmp/python /tmp/python/test.py
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/usr/local/Cellar/jython/2.7.1/libexec/jython.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Traceback (most recent call last):
File "/tmp/python/test.py", line 1, in <module>
import ij
ImportError: No module named ij
My goal is to be able to write ImageJ macros using an IDE and more advanced debugging tools than currently exist in the script editor. Python would be my preferred scripting language and PyCharm is my preferred IDE. Any thoughts would be greatly appreciated.
You need to configure your IDE to use a Jython interpreter, and have ij.jar on the PYTHONPATH of your project.
For the Eclipse IDE, there's a detailed explanation in this ImageJ forum post by Emanuele Martini.
The setup should be similar for PyCharm.

Python for .Net Error: ImportError: No module named

We are using Python for .Net to call .NET API built using C# from Python script.
We are getting ImportError: No module named - error when an import is done as follows.
Python script:
import sys
sys.path.append(r"C:\myfolderA\myfolderB")
print sys.path
import clr
clr.FindAssembly(r"AA.BB.CC")
clr.AddReference(r"AA.BB.CC")
from AA.BB.CC.Api.DDInterface import DDClient
On the above line I am getting following error
Traceback (most recent call last):
File "C:\myfolderA\myfolderB\testAPI.py", line 7, in <module>
from AA.BB.CC.Api.DDInterface import DDClient
ImportError: No module named AA.BB.CC.Api.DDInterface
There is no other information available to exactly identify the issue.
Dlls from same project built 15 days back works fine.
This project may have gone through few changes in between.
How to exactly identify this issue?
Could this be a dependency issue?
I tried JustDecompile to compare old dlls and new ones, but couldn't find anything unusual.
Your help is deeply appreciated.
Thanks,
With help from python forum I was able to use Microsoft's Fuslogvw.exe (Assembly Binding Log Viewer) and figure out the dependent dll causing the error.
Thanks
Here is a link to my original answer:
https://mail.python.org/pipermail/pythondotnet/2014-December/001626.html
I recommend using Assembly Binding Log Viewer (fuslogvw.exe) for
corresponding .NET framework to see the log files of loading assemblies.
Set Log Location as Custom and in Settings point to your assemblies folder.
The log should show the sequence of DLLs being loaded and any errors.
This worked for me, see here:
Could not load file or assembly or one of its dependencies
Can't locate fuslogvw.exe on my machine

*.pyd file fails to load, but DependancyWalker comes up clean, and ProcMon shows it loaded

I am trying to load a *.pyd with Python, but I receive the well known "Import Error: DLL load failed: the specified procedure can not be found." error.
I have already done the following:
1.) Investigated the *.pyd with Dependency Walker. GPSVC.DLL and IESHIMS.DLL came up as missing, but delay loaded, IEFRAME.DLL aslo came up as missing an export, but was also delay-loaded. It's my understanding that these are not used, and are delay load anyway, so they should not be the problem.
2.) Did an "import foo" on foo.pyd in the python command window, with ProcMon watching. ProcMon shows event "LoadImage" on "foo.pyd" with result SUCCESS.
This seems to imply that the *.pyd file loaded correctly.
So what am I missing. My windows diagnostics are telling me all is well, but python is telling me the thing cannot be loaded (usually due to a missing dll or symbol).
Ideas?
Thanks!
Is the .pyd file for the same version of Python you're using? Loading a .pyd file for the wrong Python version can produce that error message.
Dependency Walker can show you which pythonNN.dll it links to.
If you have a file foo.pyd, for import foo to succeed, there must be an externally accessible function named initfoo. Dependency Walker will show this (typically the ONLY function) if it exists. initfoo needs to be called by Python to initialise the foo module.
Note: I would expect a more explicit error message if this were the problem:
>>> import fubar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initfubar)
>>>
You say that you are "trying to load a *.pyd file". Is that just a strange way of describing import foo or is it something else?
Did you create the pyd? If not, who did? Have you asked them? Is this pyd available on the web so that others could try to load/import it?
Ok here is the answer:
The windows diagnostics (depends, procmon, etc) were showing the DLL (or pyd) loading fine.
Python was showing that it was not loading fine.
I found that the windows tools were referring to a different Python26.dll hiding in my C:\Window\SysWOW64 folder.
This second Python26.dll (found in SysWOW64) has a symbol that is missing in the primary python26.dll (installed by the windows python installer, found in C:\Python26).
This symbol "_PyByteArray_empty_string", was apparently needed by my *.pyd file.
So when loading via windows diagnostics, the SysWOW64 dll was found, and the *.pyd loaded properly. When loading from python, the dll in C:\Python26\ was found, the symbol was missing, and load failed.
So that is WHY the problem manifested. The question now is: Why are there two versions of Python26.dll floating around, one with _PyByteArray_empty_string, and one without?
I'm using Python 2.6.6. Perhaps this symbol is removed in 2.6.6 but present in some older 2.6.x release?

Categories