ericmandel / pyds9

Python connection to SAOimage DS9 via XPA
76 stars 41 forks source link

raise child_exception error (Mac OS X) #27

Closed ghost closed 8 years ago

ghost commented 8 years ago

I have recently installed both pyds9 and DS9 and can import pyds9 in python without any problems.

However when I call DS9 to open a DS9 window (d = pyds9.DS9()), it doesn't open a window, instead it gives me the following error:

d = pyds9.DS9() Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/pyds9.py", line 394, in init target] + args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

Can this be fixed?

montefra commented 8 years ago

It seems that you don't have ds9 in the path. Can you please do the following and report the results?

1) in a shell type: which ds9:

2) start python or ipython (as you prefer) and run:

import os
os.environ['PATH']

check that the output contains the path to ds9.

3) if the answert to 2) is yes, then try again to create the DS9 object. If it fails try to run:

import subprocess
subprocess.call(['ds9'])
ghost commented 8 years ago

I added the location of DS9 to the path (/Users/rem/Applications) with no luck. Importing subprocess did not work either.

ericmandel commented 8 years ago

If you are on a Mac, the DS9 "file" in Applications is not actually the program executable, it's a directory containing a bunch of files ... including the executable ... which should be in the Contents/MacOS sub-directory. For example, on my Mac, the executable is at:

/Applications/SAOImage\ DS9.app/Contents/MacOS/ds9

In your case, the ds9 executable should be here:

/Users/rem/Applications/SAOImage\ DS9.app/Contents/MacOS/ds9

And in fact, you should be able to execute that ds9 file and have DS9 come up.

If that is the case, you have three options:

  1. put /Users/rem/Applications/SAOImage\ DS9.app/Contents/MacOS in your PATH
  2. put a link to /Users/rem/Applications/SAOImage\ DS9.app/Contents/MacOS/ds9 in $HOME/bin or some other convenient bin directory
  3. just start up DS9 before you start Python and pyds9.
ghost commented 8 years ago

Aha. I understand now. I have added /Users/rem/Applications/SAOImage\ DS9.app/Contents/MacOS in my PATH. Now I get the following response:

d = pyds9.DS9() Error in startup script: couldn't read file "ds9/Frameworks/Saotk.framework/Resources/src/ds9.tcl": not a directory Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/pyds9.py", line 403, in init raise ValueError('no active ds9 running for target: %s' % target) ValueError: no active ds9 running for target: ds9

ericmandel commented 8 years ago

Hmmm ... I see that happens on my Mac as well: I can't put the MacOS directory in my path and execute ds9 from the path, but I can execute it by supplying the full path. I'll have to ask Bill Joye, ds9 author, about that.

Anyway, at this point the easiest fix is to make a shell script called ds9 containing these lines:

#!/bin/bash
open -a "SAOImage DS9" --args $*

and put the shell script in your PATH, so that this gets executed by pyds9.

The alternative, which I suspect most people end up doing, is to download the X11 version of DS9 for the Mac (and also install XQuartz ...) and put this (Linux-like) executable in your PATH somewhere.

ericmandel commented 8 years ago

... and don't forget to chmod the script so that it has execute permission:

chmod +x ds9
montefra commented 8 years ago

@maelstromscientist : did you managed to solve your problem?

ghost commented 8 years ago

Sorry for the late reply. Unfortunately I have not managed to solve this problem yet.

ericmandel commented 8 years ago

I forgot to suggest the obvious: just start up DS9 before you start Python. When you call pyds9.DS9(), it should connect to the existing DS9 instance.

ericmandel commented 8 years ago

@montefra The problem here is that there are two flavors of DS9 on a Mac: the native Aqua version and X11-based command line version. The command-line version obviously works with pyds9 if the ds9 program is in the PATH. The Aqua version once worked also, because the SAOimage DS9.app folder contained a ds9 executable that could be run from the command line. Bill Joye now tells me that this can no longer be done (and we found that to be the case empirically). So users who have installed the Aqua version only cannot easily get DS9 started automatically.

On a Mac, we could consider code like this:

  1. look for a ds9 executable in the PATH and if it exists, execute it.
  2. if not, look for /Applications/SAOimage DS9 and if it exists, run: open -a SAOimage\ DS9
  3. if neither exist, issue a warning.
montefra commented 8 years ago

@ericmandel: It's possible to do it, it's just a little change.

Is /Applications the only extra position or is there something else under the user directory?

Do we want to have it as a bugfix release with v1.8.1? If yes, we might have this out quite soon, and then I can port it to the devel branch later on.

Once it's done I'll need someone to test it on a mac.

ericmandel commented 8 years ago

The default location is /Applications, but I suppose you could check for the package in $HOME and $HOME/Applications as well. This is just a "best effort" attempt to find the package! The important thing is to issue a warning, which should say something like this:

For non-Mac (Linux):

Can't locate DS9 executable. Please add the DS9 directory to your PATH and try again.

For Mac:

Can't locate the X11 DS9 executable in your PATH or the Aqua SAOImage DS9 app in /Applications, $HOME or $HOME/Applications. Please configure your PATH or make SAOImage DS9 available in a known location.

It's a pretty simple addition, so a bug fix release is fine, if that is convenient for you. I'll test it on my Mac when you are ready.

ericmandel commented 8 years ago

Also, if you are not a Mac expert: when you look for the app, you'll be looking for a directory with a .app suffix, not an executable:

ls -ld /Applications/SAOImage\ DS9.app/
drwxr-xr-x@ 3 eric  admin  102 Nov 17 15:03 /Applications/SAOImage DS9.app/

If that directory exists, you can execute open -a on it and the program will start:

open -a /Applications/SAOImage\ DS9.app/

I don't know how you deal with the space in the directory name, depends on which Python call you make.

montefra commented 8 years ago

I think that the best is to search for ds9 when when we define the ds9Globals["progs"] entries, with the extra checks for mac.

Does it make sense to have pyds9 without a ds9 executable? If not, I'll convert the warning you suggest into exceptions, which abort the import of pyds9

Also, if you are not a Mac expert: when you look for the app, you'll be looking for a directory with a .app suffix, not an executable

Thank for the suggestion.

I don't know how you deal with the space in the directory name, depends on which Python call you make.

I think that is not a real issue. I'll figure it out.

Mostly: I hope to have the time to do it before Saturday (I'll go on vacation saturday and be back at the beginning of January).

ericmandel commented 8 years ago

Does it make sense to have pyds9 without a ds9 executable? If not, I'll convert the warning you suggest into exceptions, which abort the import of pyds9

I don't think you should abort the import. If a user has installed th Aqua version in an odd place they have the option of starting up DS9 manually before starting python. Therefore, the fact that pyds9 cannot find an executable does not meant that one is not already running!

Mostly: I hope to have the time to do it before Saturday (I'll go on vacation saturday and be back at the beginning of January).

And my vacation starts on Friday until January, so I would not worry about getting this done before we both disappear. Users currently have the option of starting up DS9 first, so there is a perfectly good method of using pyds9 on a Mac. We are just adding convnience.

montefra commented 8 years ago

@ericmandel : right; I should know it.

About the timing fine with me.

ps: If we don't interact anymore, have a Merry Christmas and a Happy New Year

ericmandel commented 8 years ago

@montefra I wish you the same! It's been a very good collaboration in 2015 and I look forward to even better things next year ...

ghost commented 8 years ago

It seems I have "solved" the problem using the above advice. I have removed all versions of DS9 except for the X11-based command line version, and added its location to my PATH. However, I must explicitly start DS9 before I can call ' d = pyds9.DS9() '. If I do not start ds9 before I execute the command then i get the child_exception error.

I'm hoping this bug gets fixed.

montefra commented 8 years ago

can you please run this command and if it fails past the whole output?

python -v "import pyds9; d = pyds9.DS9()"

ps: if the output is too long (and I guess it is), it probably better create a gist and link it here

montefra commented 8 years ago

Let's hope that #29 will solves the issue

montefra commented 8 years ago

v1.8.1 should soved this issue.

@maelstromscientist thank you for reporting it and for the patience.