Exception during Fiji/ImageJ launching from Python - python

I want to write some code in Python that will be used for manipulating data in Fiji. I followed the instructions to install the library "imagej" so that I can access Fiji via Anaconda-Python. This is how the two lines look like:
import imagej
ij = imagej.init('C:\Program Files\Fiji\Fiji.app')
However, when I run these two lines the following error shows:
JavaException: JVM exception occurred: net/imagej/updater/UpdateService
Apparently Python is trying to access Fiji Updater but it cannot (that's what I understand...)
How can I run Fiji correctly without such an error? Is there any way to disable this?

I'm no expert, and actually have no experience with interfacing via Python, but my best guess is to try turning off "check for update on start" to see if that changes anything. It may be that Python is successfully getting FIJI to run, but the first thing FIJI needs is for you to tell it whether you want to update, etc.

Related

Handling errors in Python in the console

I am currently working with a program and doing a lot of testing on it. I am using the Python logging library and write all my errors to the library. However, the errors also print directly to the console and show the entire stack trace which I do not want. Instead I would rather it just simply say error in the console and print out to the error logs.
I found this similar question here (How to make python gracefully fail?) but all answers talked about using try catches. Is there anyway to set up errors being handled this way throughout the entire program without using try-catches? I foresee them being difficult to use, for example when I quit using Control + C, which I could do at any time and may not be able to catch in a try-catch block. I would love to be able to tell my program to handle errors a certain way and have that reflected throughout the entire program.

How can I call a python function from an advanced scripting voice command in Dragon NaturallySpeaking?

How can I call a python function from an advanced scripting voice command in Dragon NaturallySpeaking?
I don't want to use a third-party application such as dragonfly or NatLink (paper).
So, one way is to compile it. You can put a bunch of functions that do different things all into the same program and pass along appropriate arguments to select the function you want, and pass the parameters along. Returning the result can be tricky, though, but I usually use the Clipboard (so copy the py output to clip and read from clip in Dragon). Multi-word params need to have spaces escaped (%20) and process it inside your py.
Something like this:
ShellExecute "path\program.exe myFunc myPar1, my%20Par%202", 6 ' 6 runs minimized
Wait 1
myVar = Clipboard
Hth,
Warning: This is not an answer. I am not a programmer. I don't know any Python and have no way of testing it.
This is just a suggestion on how to solve this problem. I don't know where else to put this. I'd put it in a comment, but it allows no screenshots. Please edit and suggest as you wish.
There is answer on SO that deals with calling Python from Excel, which is a similar concept: https://stackoverflow.com/a/3569988/2101890. I am trying to use that here but don't know how.
When using commands in another programming language, you can sometimes add them by adding a reference in the MyCommands Editor. You can reference DLLs and other "stuff". Some references to libraries appear automatically. I've installed Python and hoped to find Python in the References, but no such luck:
There is no Python entry here that I can find. You may have better luck. If you do find something, check the box and see if you can add python commands without causing an error when saving the command.
Maybe you can browse to %localappdata%\Programs\Python\Python36\ and add some of the DLLs from there and call Python commands from there. Or try getting it to work in the way described under 1.

iPython history of valid commands

I am learning python using IPython. When I did something nice I like to copy this into some kind of private CheatSheet-file. Therefore I use the iPython %hist command. I am wondering, if there is a way to only print those commands which had been syntactically correct and did not raise an error. Any ideas?
Have you considered trying ipython notebook ? (I've used it on a couple of training courses)
You access the interatctive python via a web browser creating 'boxes' of runnable code. So if you ran a block, it gave the answer you wanted and threw no errors, you could then create another block and move on (preserving the bit you wished to keep). If it threw an error or didn't produce the expected result, you could edit and re-run until it did.
Your boxes of code can be interspersed with html markup notes, graphs, diagrams - you name it.
The whole notebook can then be saved for later access and re-run when re-loaded.

Gnumeric Python plugin : service file_opener and file_saver

Is it possible to write a gnumeric python plugin for the file_opener and file_saver service?
It seems implemented in the python-loader plugin, there are corresponding sections in the Gnome documentation.
But the example plugin gnome-glossary, which is python file_saver plugin, raises an error ImportError: No module named gsf and I can't write in the output object given by the API:
def so_file_save(wb, output):
output.props.write("toto")
produces the error :
Exception Python (<type 'exceptions.AttributeError'> : 'gobject.GProps' object has no attribute 'write')
And this gobject.GProps object claim to be of __gtype__ : GsfOutputStdio
The python bindings for 'libgsf' are unsupported since a long time ago. As you can read in the old README-python:
I wrote these bindings in 2002, and they haven't been updated since.
They were never part of a standard build, but it was possible to build
them by following the instructions below. It will probably take some
work to make them work with current versions of autotools and
pygobject. Bindings would have to be revalidated, and extended to
match the current API of libgsf.
I do not plan to do further work on these bindings. If anybody wants
to pick them up, please feel free.
Jon K Hellan [...] 2006-02-24
That explaines why gnome-glossary fails. Also, it seems to be a problem with the parameter output, which is shown as a GObject, but not as GsfOutputStdio (you only can see the properties, but you do not have access to any method.
This is not the solution you are looking for, but an attempt of explanation of what you are seeing.

Excel RTD server in Python not updating data

I've got the excelRTDserver.py up and running in Excel 2010 (32bit) by changing the EXCEL_TLB_MINOR value to 7. I can see the server in the add-ins list and if I enter =RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the current time. But it never updates. If I change the "5" to another number, I get an update but after the initial change it never changes again.
How do I get it to update? I found someone else with a similar problem here, but no solution.
UPDATE: I've got a little further - there is an exception raised within ServerStart when casting the PyIDispatch callback object into a IRTDUpdateEvent callback object. Using this method to capture the error message, I get "Cannot create a file when that file already exists.". If I follow the suggestion here and use win32com.client.CastTo(CallbackObject,'IRTDUpdateEvent') I get "This COM object can not automate the makepy process - please run makepy manually for this object", but I have already run makepy for Microsoft Excel 12.0 Object Library (1.6).
Any help would be greatly appreciated.
To work around this problem I've created a new project on github for pythoncom excel types:
https://github.com/pyxll/exceltypes
This includes a slightly modified version of excelRTDServer.py that uses the new type PyIRTDUpdateEvent instead of the win32com makepy wrapper, and so it now works in Excel 2010 (look for the comments 'EXCELTYPES_MODIFICATION' in exceltypes/demos/excelRTDServer.py).
To build the project you will need visual studio installed (it won't build with gcc) and you can build it using the setup.py included in the project as follows:
python setup.py install
If you need to force it to use visual studio instead of gcc use the "--compiler=msvc" option, if you're using anaconda for example.
If you want to use Visual Studio 2012 instead of the default 2010 add the following lines to setup.py:
from distutils import msvc9compiler
msvc9compiler.VERSION = 11
I think you may be out of luck.
According to the author of excelRTDServer.py in a recent python-win32 thread:
The message that this is in response to describes your exact problem, and it's recent, so maybe you already got this info directly, but in case you didn't...
I fear that things with IRTDUpdateEvent have changed with recent versions
of excel (since Excel 2007? I guess that's not so 'recent' anymore...).
While hunting around for news of interface changes, I came across this
thread in a java forum:
http://www.nevaobject.com/phpbb3/viewtopic.php?t=516
The part that worries me is this comment:
"Apparently in Excel 12 (Excel 2007) the RTD callback object that
implements dual IRTDUpdateEvent interface throws exception (generic COM
exception 0x80020009) when is called via IDispatch. If you use v-table
binding the call to UpdateNotify succeeds. I don't really know whether it
is a bug in Excel 12 or a feature."
So far I haven't been able to confirm this against the MSDN information...
But if this is true, it does explain the problem being seen. Many older
examples on the web, and pywin32+makepy treat this interface as IDispatch,
and wrap it accordingly.
I don't think we can fix this with pywin32 as it is right now. My
understanding is that it relies on IDispatch support. May need to look at
comtypes (http://starship.python.net/crew/theller/comtypes/) to wrap the
(new?) IRTDUpdateEvent objects, or maybe a C extension. :(
Python:
I get "This COM object can not automate the makepy process - please run makepy manually for this object", but I have already run makepy for Microsoft Excel 12.0 Object Library (1.6).
Yesterday at work after a while reading your question, I forgot that is python and not java :)).. Well, the only thing I think now is that seems you need to run the PIA for office 2010.
Edit later: if you steel have problems after what i told you., please comment and not downvote, because this issue is uncommon.
JAVA:
This happen because is missing the option to generate v-tables.
You need to modify ServerStart method and also IRTDServer interface and IRTDServer_Impl class., so CallbackObject is COMIUnknown. Then you need to generate IRTDServer_Skel class by runing the IBuilder.
Now you can generate a new java wrapper for IRTDUpdateEvent to request v-table:
That error message sometimes is raised when u put it in something like 'for'-loop,here is a hackly solution 4u:import time,and use 'sleep()' in your loop
The IRTDUpdateEvent problem (throwing exception) as described in here should be fixed in the latest Office 365 version.
"Apparently in Excel 12 (Excel 2007) the RTD callback object that implements dual IRTDUpdateEvent interface throws exception (generic COM exception 0x80020009) when is called via IDispatch. If you use v-table binding the call to UpdateNotify succeeds. I don't really know whether it is a bug in Excel 12 or a feature."
Therefore excelRTDserver.py should work fine with the latest version of Office. In other words, =RTD("Python.RTD.TimeServer","","seconds","5") should continuously get updated as expected.

Categories