Three problems or characteristics of Unix-related methods and class

Hi there,

While testing pip install pyphen and the python code by @jordan within SuperCollider 3.13.0 on MacOS and Windows, I found the following problems (?) with Unix-related methods and classes. In this thread I will only use the example of pip install pyphen to briefly describe the problem, but the same thing happens with @jordan’s code.

Problem 1

When using all Unix-related methods and the Pipe class except .runInTerminal, SuperCollider under MacOS does not know the paths for python and pip. So the following code will work as expected:

"pip install pyphen".runInTerminal

but any of the following codes will not work under macOS:

"pip install pyphen".unixCmd
"pip install pyphen".systemCmd
"pip install pyphen".unixCmdGetStdOut
"pip install pyphen".unixCmdGetStdOutLines
(
var p, l;
p = Pipe.new("pip install pyphen", "r");
l = p.getLine;
while({l.notNil}, {l.postln; l = p.getLine; });
p.close;
)

The above codes should be rewritten with the path for pip as follows:

"/Users/prko/opt/anaconda3/bin/pip install pyphen".unixCmd
"/Users/prko/opt/anaconda3/bin/pip install pyphen".systemCmd
"/Users/prko/opt/anaconda3/bin/pip install pyphen".unixCmdGetStdOut
"/Users/prko/opt/anaconda3/bin/pip install pyphen".unixCmdGetStdOutLines
(
var p, l;
p = Pipe.new("/Users/prko/opt/anaconda3/bin/pip install pyphen", "r");
l = p.getLine;
while({l.notNil}, {l.postln; l = p.getLine; });
p.close;
)

Why is this happening on MacOS? On Windows we do not need to specify the path for pip and python. I have not tested this on Linux. Does anyone know what happens on Linux?

Problem 2
systemCmd, unixCmdGetStdOut, unixCmdGetStdOutLines and Pipe only respond at odd times on Windows.

runInTerminal works as expected:

"pip install pyphen".runInTerminal

Each time the above code is evaluated, sclang returns the following strings in the post window of SC-IDE, and executes the command by running a command prompt window.

-> pip install pyphen

Evaluating the following code will always work correctly,

"pip install pyphen".unixCmd

and will always return the following results on those occasions:

-> 38304
Requirement already satisfied: pyphen in c:\users\prko\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (0.14.0)

However, the following code

"pip install pyphen".systemCmd

and the following code

(
var p, l;
p = Pipe.new("pip install pyphen", "r");
l = p.getLine;
while({l.notNil}, {l.postln; l = p.getLine; });
p.close;
)

return the following strings in the post window of the SC-IDE only on odd times, such as the first time, the third time, and so on, of evaluating the code, and it returns no result on even times, such as the second time, the fourth time, and so on:

Requirement already satisfied: pyphen in c:\users\prko\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (0.14.0)
-> 0

Also, the following code

"pip install pyphen".unixCmdGetStdOut

returns the following strings in the post window of the SC-IDE only on odd times, such as the first time, the third time, and so on, of evaluating the code, and it returns no result on even times, such as the second time, the fourth time, and so on:

-> Requirement already satisfied: pyphen in c:\users\prko\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (0.14.0)

Also, the following code

"pip install pyphen".unixCmdGetStdOutLines

returns the following strings in the post window of the SC-IDE only on odd times, such as the first time, the third time, and so on, of evaluating the code, and it returns no result on even times, such as the second time, the fourth time, and so on:

-> [ Requirement already satisfied: pyphen in c:\users\prko\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (0.14.0) ]

Under MacOS it always returns its result if pip and python are specified with the correct path. Why do systemCmd, unixCmdGetStdOut, unixCmdGetStdOutLines and Pipe only respond at odd times on Windows? What about them on Linux?

Problem 3
systemCmd, unixCmdGetStdOut, unixCmdGetStdOutLines and Pipe interfere with each other, so the things described in Problem 2 occur across these things.

Are these characteristics bugs or not?

Thanks in advance!

I’m not too familiar with mac, but its odd that you are using the anaconda version of python as opposed to the system’s. What does which python and which pip return? Sometimes python can be a real pain when it comes to multiple versions and virtual environments…

Works as expected. But if this is a python version issue, most linux users probably have python setup correctly so that might not be a OS issue per-say.

Can’t comment on the rest as I only ever use .unixCmd & .unixCmdGetStdOut.

On macOS, which python returns /Users/prko/opt/anaconda3/bin/pip, and
which pip returns /Users/prko/opt/anaconda3/bin/python.

This is a classic setup on mac, and making environement, not to pollute the (old) python that mac os needs for some maintenance and tasks.

I had to learn all this the hard way - having a poluted Pythion 2.7 was REALLY fun :slight_smile:

Is that from inside supercollider, i.e., do unixCmd, systemCmd … return different things?
Likewise, it might be worth seeing if whoami differs?

On my system (MacOS), the environment variable $PATH is different in the terminal than when running eg. unixCmd:

"echo $PATH".unixCmd
// -> /usr/bin:/bin:/usr/sbin:/sbin
"echo $PATH".runInTerminal
// -> Lots and lots of paths

I would guess your anaconda paths are set in your shell profile file, (.bashrc, .bash_profile or similar), which SuperCollider doesn’t pick up. I don’t know if there’s a way making that happen, but my workaround has been to supply absolute paths…

"which python".runInTerminal

returns:

/Users/prko/opt/anaconda3/bin/pip
"which pip".runInTerminal

returns:

/Users/prko/opt/anaconda3/bin/python
"whoami".runInTerminal

returns:

prko

The three codes above are sclang codes, but the terminal commands are executed in the terminal window. So the results are the same as if one executed the commands directly in the terminal window.

However, the following results are different:
The following code

"which python".unixCmd

returns:

-> 32509

and the following code

"which pip".unixCmd

returns:

-> 32511

and the following code

"whoami".unixCmd

returns:

-> 32512
prko

With .systemCmd, the following code

"which python".systemCmd

returns:

-> 256

and the following code

"which pip".systemCmd

returns:

-> 256

and the following code

"whoami".systemCmd

returns:

prko
-> 0

Oh, thank you! Your diagnosis seems perfectly accurate! It would be nice if sclang could pick up all these paths!

I now know the cause of the Problem 1. Under macOS 12.6.5, there is no python file and pip in the system path, but pyhon3 and pip3.

The following code

"which python3".unixCmd

returns:

/usr/bin/python3

and the following code

"which pip3".unixCmd

returns:

-> 1507
/usr/bin/pip3

So the followings work if one uses only the system default python3:

"pip3 install pyphen".unixCmd

The code above returns:

-> 1511
Defaulting to user installation because normal site-packages is not writeable
Collecting pyphen
  Downloading pyphen-0.14.0-py3-none-any.whl (2.0 MB)
Installing collected packages: pyphen
Successfully installed pyphen-0.14.0

The following code

"pip3 install pyphen".systemCmd

and the following code

(
var p, l;
p = Pipe.new("pip3 install pyphen", "r");
l = p.getLine;
while({l.notNil}, {l.postln; l = p.getLine; });
p.close;
)

returns:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pyphen in /Users/prko/Library/Python/3.9/lib/python/site-packages (0.14.0)
-> 0
"pip3 install pyphen".unixCmdGetStdOut

The code above returns:

-> Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pyphen in /Users/prko/Library/Python/3.9/lib/python/site-packages (0.14.0)
"pip3 install pyphen".unixCmdGetStdOutLines

The code above returns:

> [ Defaulting to user installation because normal site-packages is not writeable, Requirement already satisfied: pyphen in /Users/prko/Library/Python/3.9/lib/python/site-packages (0.14.0) ]

And the following code

"pip3 install pyphen".runInTerminal

runs a terminal window, and the result is as follows:

Last login: Wed May 17 12:19:39 on ttys001
/Users/prko/Library/Application\ Support/SuperCollider/tmp/SCStringForTerminal1571796326.command ; exit;
prko@PyoungRyangs-Virtual-Machine ~ % /Users/prko/Library/Application\ Support/SuperCollider/tmp/SCStringForTerminal1571796326.command ; exit;
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pyphen in ./Library/Python/3.9/lib/python/site-packages (0.14.0)

Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

I think Problem 1 has been solved.