ericmandel / pyds9

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

Problem running pyds9 #95

Open dalilas98 opened 4 years ago

dalilas98 commented 4 years ago

When I run the code given on GitHub to use ds9, I receive this error "raise ValueError('no active ds9 running for target: %s' % target)" It was working perfectly before and I'm unsure what the problem is

DougBurke commented 4 years ago

Could you include the actual code you used, what python version, and the version of pyds9 used (or how you installed it)?

dalilas98 commented 4 years ago

import pyds9 print (pyds9.ds9_targets()) d = pyds9.DS9()

I'm using python 3.7 and the most updated version of pyds9.

DougBurke commented 4 years ago

Sorry for being nit-picky, but when you say the most updated version do you mean the master branch of github? I also forgot to ask what OS you are using?

Ta

On Fri, Apr 10, 2020 at 10:14 AM dalilas98 notifications@github.com wrote:

import pyds9 print (pyds9.ds9_targets()) d = pyds9.DS9()

I'm using python 3.7 and the most updated version of pyds9.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ericmandel/pyds9/issues/95#issuecomment-612046712, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABW27XS5NFFTJSJP3COIMDRL4STVANCNFSM4MEEGEZQ .

dalilas98 commented 4 years ago

No you're fine. I'm using MacOS and yes the master branch.

DougBurke commented 4 years ago

Unfortunately I don't have a macOS machine to debug.

Do you have an idea of what version was working (or even if you're able to run some bisection with the master branch, either manually or with git)?

ericmandel commented 4 years ago

@dalilas98 This works for me on my Mac with a freshly installed copy of pyds9. I'm guessing that, in your case, the DS9 program is being started up by the pyds9.DS9() call, but the default 10 second wait time is too short (possibly because it takes a long time to start up the X server?). You can test this theory by extending the wait time:

d = pyds9.DS9(wait=60)

and see if that fixes things.

It's also possible that there is a mixup between the XPA_METHOD used by DS9 and the XPA_METHOD used by Python/pyds9. Did you set the XPA_METHOD environment variable at any point? Do you already have an xpans program running before starting Python?

ericmandel commented 4 years ago

@dalilas98 btw, if you are getting an error after a long delay (e.g. 30 to 120 secs), the probable cause is your Mac firewall not allowing connections to xpans. That is, some time in the past, you might have denied xans access to incoming conections. You can check/fix this in the System Preferences -> Security and Privacy -> Firewall -> Firewall Options tab.

kenearnold16 commented 4 years ago

Hi @ericmandel I tried setting the wait time to 60 and I also have the firewall disabled in my system preferences but I still get the error. If I understand it correctly could there be a problem with the inet sockets that ds9 and xpa are using to communicate with each other?

ericmandel commented 4 years ago

Yes, this seems to be an inet socket problem. You can try a different XPA socket communication method:

export XPA_METHOD=local               # use local (file) unix sockets

or:

export XPA_METHOD=localhost        # use the localhost (127.0.0.1) instead of hostname socket

Note that this environment variable should be set before starting Python.

kenearnold16 commented 4 years ago

I just want to make sure that I am doing this correctly, do I type these commands into the terminal(base) on my mac? If so this seems not to be working either.

ericmandel commented 4 years ago

Yes, you do this (assuming you are using the bash and ds9 is not running yet):

export XPA_METHOD=local
python3
>>> import pyds9
>>> d = pyds9.DS9()
ericmandel commented 4 years ago

Once you have set XPA_METHOD, as a check, you can start up ds9 manually and then look at File->XPA->Information and for local sockets, you should see a filename:

Screen Shot 2020-04-12 at 12 52 15 PM
ericmandel commented 4 years ago

Which version of ds9 are you running? I am running the X11 version of v8.1.

Is DS9 starting up??

kenearnold16 commented 4 years ago

When I type the commands into the terminal ds9 does start up but when I check the XPA information it displays 7f000001:54215. I am running v8.1 but I am unsure if it is the X11 how can I check if it is X11?

kenearnold16 commented 4 years ago

I am mostly trying to get the module to work on spider from anaconda which is where I get the error message.

ericmandel commented 4 years ago

If you set XPA_METHOD to local in the shell that eventually starts up ds9, but are seeing 7f000001:54215 as ds9's XPA method, then something is wrong: that is still the inet method being used. I would look for a ds9 script in your PATH (which is what pyds9 is finding and using to start up ds9). If you find a script, post it here. I hope it doesn't blithely set XPA_METHOD to inet!

ericmandel commented 4 years ago

I am unsure if it is the X11 how can I check if it is X11?

The X version looks like this:

Screen Shot 2020-04-12 at 1 45 55 PM

When its running, you'll also see the X11 server running, with the usual X11 dock icon:

Screen Shot 2020-04-12 at 1 48 09 PM

The Aqua version looks more like a Mac app, I don't have it installed, but its much different.

ericmandel commented 4 years ago

OK, I've installed the Aqua version of DS9, and it also works with pyds9 on my machine. Aqua DS9 looks like this:

Screen Shot 2020-04-12 at 2 29 42 PM

I've run it both using inet and local sockets. I'm pretty sure this is an inet socket problem with the complication of not successfully switching to local sockets.

kenearnold16 commented 4 years ago
Screen Shot 2020-04-12 at 2 55 39 PM

This is the out I get when I export XPA_METHOD and check the path

ericmandel commented 4 years ago

To find ds9 in your PATH, you have to do something like:

which ds9

For example, I get:

which ds9
/Users/eric/bin/ds9

You can find out what type of file this is using (to continue the example):

file /Users/eric/bin/ds9
/Users/eric/bin/ds9: Mach-O 64-bit executable x86_64

which means I have the ds9 executable in my path, not a script. If you have a script it will say something like:

POSIX shell script text executable, ASCII text

and in that case, you should just show its contents.

kenearnold16 commented 4 years ago

So I successfully got the XPA_METHOD to change in DS9 now when I open the information it says XPA_METHOD: /var/folders/8b/64_1pvzn11z6y1s35jnvn53c0000gp/T//DS9_ds9.39095 but when I try to find ds9's path the terminal says that ds9 is not found.

Screen Shot 2020-04-12 at 3 28 03 PM
kenearnold16 commented 4 years ago

From the terminal pyds9 executes successfully but it still stalls from spyder.

ericmandel commented 4 years ago

From the terminal pyds9 executes successfully but it still stalls from spyder.

Sorry, I know nothing about spyder or anaconda or Python for that matter. @DougBurke is trying to help with Python-specific issues (as opposed to the xpa/network/etc issues we have talking about today) and he might be able to make a suggestion ...

ericmandel commented 4 years ago

For example, I have no idea anaconda is finding ds9 if it doesn't appear in your PATH ...

dalilas98 commented 4 years ago

I successfully ran the export XPA_METHOD=local command but I'm sill receiving the same error.

File "/opt/anaconda3/lib/python3.7/site-packages/pyds9.py", line 449, in init raise ValueError('no active ds9 running for target: %s' % target) ValueError: no active ds9 running for target: ds9

Also I don't have a path when I type which ds9.

ericmandel commented 4 years ago

My confusion: is DS9 starting up successfully but you are erroneously getting this message, or is DS9 not starting successfully and the error message is correct but unwanted?

dalilas98 commented 4 years ago

My apologies for the confusion. The command that gives me an error is " d = pyds9.DS9()" I tried the solution above but none of them are correcting my error.

ericmandel commented 4 years ago

No I understand that ... what I don't understand is the status of DS9 when you execute pyds9.DS9(). The possibilities are:

  1. ds9 is already running then you execute pyds9.DS9() and you erroneously get the message
  2. ds9 is not yet running and is started up by pyds9.DS9() (as it should be by default, unless you pass the start=False flag) and you erroneously get the message
  3. ds9 is not yet running and is not started up by pyds9.DS9() as it should be, and you get a correct message
  4. some other?

Which situation are we dealing with?

dalilas98 commented 4 years ago

Ds9 is not yet running and is started up by the command and I get the error message.

ericmandel commented 4 years ago

OK, so the thing to check is whether both pyds9 and DS9 are using the same XPA transport mechanism. To do this, run pyds9.DS9() and in Python, check the _method property. On my Mac, I have XPA_METHOD set to local, so I see this:

>>> d = pyds9.DS9()
>>> d._method
'local'

Then check DS9 File -> XPA -> Information. I see a local file like this:

XPA_VERSION:    2.1.18
XPA_CLASS:  DS9
XPA_NAME:   ds9
XPA_METHOD: /var/folders/hl/0rxttnz48xldqq006s7f7t980000gp/T//DS9_ds9.43145

If I am using inet sockets, I will see this:

>>> d = pyds9.DS9()
>>> d._method
'inet'

and

XPA_VERSION:    2.1.18
XPA_CLASS:  DS9
XPA_NAME:   ds9
XPA_METHOD: 7f000001:56341

What do you see?

kenearnold16 commented 4 years ago

@ericmandel I was able to communicate successfully with spyder but I had to create a SampHub with astropy

Screen Shot 2020-04-13 at 10 14 55 PM

After I set this up I am able to communicate with ds9 using pyds9 with no problem

ericmandel commented 4 years ago

@kenearnold16 How weird! Of course, pyds9 has nothing to do with samp, but whether either DS9 or spyder is in some strange configuration requiring samp I cannot say. Perhaps @wjoye might have some insight into the DS9 side, or @DougBurke into spyder. Really strange ...

wjoye commented 4 years ago

Ds9 support for samp does not include a samp hub.

Sent from my iPad

On Apr 13, 2020, at 11:29 PM, Eric Mandel notifications@github.com wrote:

 @kenearnold16 How weird! Of course, pyds9 has nothing to do with samp, but whether either DS9 or spyder is in some strange configuration requiring samp I cannot say. Perhaps @wjoye might have some insight into the DS9 side, or @DougBurke into spyder. Really strange ...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

DougBurke commented 4 years ago

I have no experience with spyder. I also wonder if the issue for @kenearnold16 was different to the original reporter, @dalilas98 [I haven't been following this closely enough]

ericmandel commented 4 years ago

OK, @kenearnold16, this looks like a spyder problem (since pyds9 knows nothing about samp, and DS9 does, but does not support a samp hub), so someone with expertise re: spyder will have to look into this. Perhaps you know someone who can help? Or perhaps you found yourself a satisfactory work-around?

kenearnold16 commented 4 years ago

To me it appears that the problem with spyder is that I can't send or receive data at all with pyds9, however if I try from the base terminal there's no issues sending and receiving data. In spyder if I create the hub I can successfully send and receive data and then afterwords I can use d.set() or d.get() to manipulate and adjust data in ds9 how I like. The code I have in spyder seems to be working so far I think I've got it from here. Thank you!

dalilas98 commented 4 years ago

I fixed my previous error, but now when I try to import pyds9 it says

Traceback (most recent call last): File "", line 1, in File "/Users/dscott09/Desktop/pyds9-master/pyds9/init.py", line 20, in from .pyds9 import * File "/Users/dscott09/Desktop/pyds9-master/pyds9/pyds9.py", line 31, in from . import xpa File "/Users/dscott09/Desktop/pyds9-master/pyds9/xpa.py", line 33, in raise ImportError("can't find XPA shared library") ImportError: can't find XPA shared library

ericmandel commented 4 years ago

The XPA library is compiled during install, so might this indicate that the compile was not done? Here us what I see when installing pyds9:

eric% pip3 install git+https://github.com/ericmandel/pyds9.git#egg=pyds9
Collecting pyds9
  Cloning https://github.com/ericmandel/pyds9.git to /private/var/folders/hl/0rxttnz48xldqq006s7f7t980000gp/T/pip-install-41_lhako/pyds9
  Running command git clone -q https://github.com/ericmandel/pyds9.git /private/var/folders/hl/0rxttnz48xldqq006s7f7t980000gp/T/pip-install-41_lhako/pyds9
  Running command git submodule update --init --recursive -q
Requirement already satisfied: astropy in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pyds9) (3.1.2)
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pyds9) (1.16.4)
Installing collected packages: pyds9
    Running setup.py install for pyds9 ... done
Successfully installed pyds9-1.9.dev0

with a noticable delay at the setup.py line while xpa is being compiled. You could try uninstall and then re-install to see what happens on your machine.

dalilas98 commented 4 years ago

That worked for the XPA error, thank you. However, it now is back to this error

d = pyds9.DS9() Traceback (most recent call last): File "", line 1, in File "/Users/dscott09/opt/anaconda3/lib/python3.7/site-packages/pyds9.py", line 449, in init raise ValueError('no active ds9 running for target: %s' % target) ValueError: no active ds9 running for target: ds9 d.set("file /Users/dscott09/Downloads/casa_0.5-1.5keV.fits") Traceback (most recent call last): File "", line 1, in NameError: name 'd' is not defined

ericmandel commented 4 years ago

@dalilas98 If you are still in this state of affairs (see above):

Ds9 is not yet running and is started up by the command and I get the error message.

please work through the suggestions above that start:

OK, so the thing to check is whether both pyds9 and DS9 are using the same XPA transport