Dyalog / pynapl

Dyalog APL ←→ Python interface
MIT License
74 stars 10 forks source link

Dyalog APL could not initialise because the script file could not be opened #16

Open justin2004 opened 2 years ago

justin2004 commented 2 years ago

dyalog version 18.0.4068 Python 3.9.2 Debian 11

root@debian-s-1vcpu-1gb-nyc3-01--google-home:~/pynapl# ls -l
total 44
-rw-r--r-- 1 root root  1068 Dec 19 17:31 LICENSE
-rw-r--r-- 1 root root   145 Dec 19 17:31 MANIFEST.in
-rw-r--r-- 1 root root 21762 Dec 19 17:31 README.md
drwxr-xr-x 6 root root  4096 Dec 19 17:31 demos
drwxr-xr-x 4 root root  4096 Dec 19 17:33 pynapl
-rw-r--r-- 1 root root  1194 Dec 19 17:31 setup.py
root@debian-s-1vcpu-1gb-nyc3-01--google-home:~/pynapl# which dyalog
/usr/bin/dyalog
root@debian-s-1vcpu-1gb-nyc3-01--google-home:~/pynapl# python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pynapl import APL
>>> apl=APL.APL()

Dyalog APL could not initialise because the script file could not be opened

any tips?

rodrigogiraoserrao commented 2 years ago

Hey there, @justin2004.

In order for Python to start Py'n'APL, it tries writing a little auxiliary file so that APL knows what port to connect to. It may be that Python doesn't have permission to create said auxiliary file.

Can you check if this is what's happening?

justin2004 commented 2 years ago

hi @RojerGS

execution does not make it past this line: https://github.com/Dyalog/pynapl/blob/8b17bceda64b182cf89f4c9b7b77580ec9daf2ed/pynapl/APLPyConnect.py#L444

but the FIFOs do get created:

>>> from pynapl import APL
>>> apl=APL.APL(debug=True)
in:  /tmp/tmpno0hd1fa
out:  /tmp/tmp_fdhz513

and i see them in the /tmp/ directory.

i guess i'll strace python later to see why it can't open a FIFO it created.

justin2004 commented 2 years ago

it might also be that dyalog isn't starting:

root@debian-s-1vcpu-1gb-nyc3-01--google-home:~/pynapl# ps -ef | grep dyalog
root       99298   96042  0 16:11 pts/7    00:00:00 grep dyalog
rodrigogiraoserrao commented 2 years ago

Mind that, when using APL.APL(debug=True), the line of code that starts Dyalog ) is skipped: https://github.com/Dyalog/pynapl/blob/8b17bceda64b182cf89f4c9b7b77580ec9daf2ed/pynapl/APLPyConnect.py#L437

If you don't set debug=True, does Dyalog start?

i guess i'll strace python later to see why it can't open a FIFO it created. If you could do that, I'd appreciate it.

justin2004 commented 2 years ago

@RojerGS i got it to work with this patch:

diff --git a/pynapl/RunDyalog.py b/pynapl/RunDyalog.py
index 2166877..1a0572f 100644
--- a/pynapl/RunDyalog.py
+++ b/pynapl/RunDyalog.py
@@ -46,7 +46,7 @@ def posix_dythread(inf,outf, dyalog=b"dyalog"):
     path=to_bytes(os.path.dirname(SCRIPTFILE))+b'/Py.dyalog'

     # Run the Dyalog instance in this thread
-    p=Popen([dyalog, b'-script'], stdin=PIPE, preexec_fn=os.setpgrp)
+    p=Popen([dyalog], stdin=PIPE, preexec_fn=os.setpgrp)
     s=script%(pystr(ipcpath),pystr(path),inf,outf)
     p.communicate(input=s.encode('utf8'))

my session:

root@debian-s-1vcpu-1gb-nyc3-01--google-home:~/pynapl# ipython3 --TerminalInteractiveShell.editing_mode=vi
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.

[nav] In [1]: from pynapl import APL

[nav] In [2]: apl=APL.APL()
Dyalog APL/S-64 Version 18.0.40684
Serial number: UNREGISTERED - not for commercial use
+-----------------------------------------------------------------+
| Dyalog is free for non-commercial use but is not free software. |
| A non-commercial licence can be used for experiments and        |
| proof of concept until the point in time that it is of value.   |
| For further information visit                                   |
| https://www.dyalog.com/prices-and-licences.htm                  |
+-----------------------------------------------------------------+
Copyright (c) Dyalog Limited 1982-2021

          ⎕PW←32767
          {}2⎕FIX'file:///root/pynapl/pynapl/IPC.dyalog'
          {}2⎕FIX'file:///root/pynapl/pynapl/Py.dyalog'
          infile←'/tmp/tmpb7d69bix'
          outfile←'/tmp/tmp7v_m7rgd'
          Py.StartAPLSlave infile outfile
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

[ins] In [3]: apl.eval("⍳ 3")
Out[3]: [1, 2, 3]
rodrigogiraoserrao commented 2 years ago

How did you come to the conclusion that you should remove b'script' from there?

And is it working decently, now?

justin2004 commented 2 years ago

i ran dyalog -script saw that i got the same error message:

Dyalog APL could not initialise because the script file could not be opened

and started iterating on variations around that. also i didn't even see the -script option mentioned in the dyalog command line interface guide.

And is it working decently, now?

yup. but i've only done apl.eval() which i think is all i will care about.

justin2004 commented 2 years ago

the only way i have been able to get this project to work under a linux distro is to apply this patch.

it seems like this project is only used by people using MS windows?

0racle commented 1 year ago

Applying the patch above also fixes the error for me.

Re: Removing the -script flag, later versions no longer support this flag under Linux. Instead a dyalogscript bash script is provided.

See Shell Scripts.