Page 1 of 2

Check if Python 3 installed?

Posted: Sun Mar 13, 2022 10:24 am
by Zax
Hello,

I used Python 2.7 (pre-installed with my MacOs version) with a LC stack and I was able to check if Python is intalled with something like:

Code: Select all

function isPythonInstalled
   get shell("python --version")
   return (char 1 to 13 of it <> "/bin/sh: line")
end isPythonInstalled
Now I need to use Python 3.
When I type "python3 --version" in the Mac Console, it returns "Python 3.7.8rc1". But it doesn't work when I use in my stack:

Code: Select all

get shell("python3 --version") 
I suppose the problem comes from where Python 3 was installed but I don't understand why the Console returns the correct answer and not the shell command sent from my LC stack.

For informations: "which -a python python2 python2.7 python3 python3.6" typed in the Mac Console returns:
/usr/bin/python
/usr/bin/python2.7
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3
So, I know where Python 3 was installed on my machine, but how could I check from my LC stack if Python 3 is installed on other computers?

Thank you.

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:00 am
by richmond62
This worked over on my machine (MacOS 12.3):
-
SShot 2022-03-13 at 11.59.44.png
-
and so did this:
-
SShot 2022-03-13 at 12.02.18.png
SShot 2022-03-13 at 12.02.18.png (19.45 KiB) Viewed 6750 times

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:17 am
by Zax
Thanks for your quick reply but, I as said, this doesn't work for me from LC.

In message box:

Code: Select all

put shell("python3 --version")
--> /bin/sh: line 1: python3: command not found

Code: Select all

put shell("which python3")
--> [empty]

Though, all of these commands work fine from the Mac console (Mac OS Sierra 10.12.6 with Python 2.7 pre-installed).
Python 3 was manually installed.

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:26 am
by richmond62
This:

Code: Select all

on mouseUp
   put shell ("which python3")
end mouseUp
gave me: /usr/bin/python3

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:32 am
by Zax
Sorry, forget "console", it's Terminal.

Python 2:
py2.jpg
Python 3:
py3.jpg

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:42 am
by richmond62
Sorry, forget "console", it's Terminal.
Ce n'est pas un problem, c'etait un problem avec mon cerveau . . . 8)

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:43 am
by Zax
richmond62 wrote:
Sun Mar 13, 2022 11:42 am
Ce n'est pas un problem, c'etait un problem avec mon cerveau . . . 8)
:D

My brain also have problems with english, shell... and python ;)

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 11:44 am
by richmond62
But this:

Code: Select all

on mouseUp
   put shell ("python - - version")
end mouseUp
is no good at all: /bin/sh: line 1: python: command not found
-
brain.jpeg

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 12:00 pm
by SparkOut
I don't have any idea whether it would be similar on another OS but on Windows to make a shell call like that, then python would need to be included in the user's "path". If not, you would need to make the shell call with the full location of the python executable.
Can you examine the PATH and determine whether python is included? That might tell you all you need, or possibly tell you what a shell call would need to get a result.

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 12:02 pm
by Zax
To simplify:

From Terminal:

Code: Select all

python --version
--> Python 2.7.10

From LC:

Code: Select all

put shell("python --version")
--> Python 2.7.10



From Terminal:

Code: Select all

python3 --version
--> Python 3.7.8rc1

From LC:

Code: Select all

put shell("python3 --version")
--> /bin/sh: line 1: python3: command not found
:(

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 12:06 pm
by Zax
SparkOut wrote:
Sun Mar 13, 2022 12:00 pm
I don't have any idea whether it would be similar on another OS but on Windows to make a shell call like that, then python would need to be included in the user's "path". If not, you would need to make the shell call with the full location of the python executable.
Can you examine the PATH and determine whether python is included? That might tell you all you need, or possibly tell you what a shell call would need to get a result.
You're right, but I don't know how to examine the PATH from LC, as shell commands sent from LC return error.
I know Python 3 path on my machine, but I don't know how to find it from LC on other machines, so I will be unable to test if Python 3 is intalled when I'll try to run my LC standalone on other machines.

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 12:10 pm
by SparkOut
I think

Code: Select all

get shell ("echo $PATH")
might get a list?

This looks useful, maybe? https://opensource.com/article/19/5/pyt ... efault-mac

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 12:58 pm
by Zax
SparkOut wrote:
Sun Mar 13, 2022 12:10 pm
I think

Code: Select all

get shell ("echo $PATH")
might get a list?
Interesting, but only the PATH of Python 2 (pre-installed) is returned.

Of course, I could write a little function in the .py file required by my stack to return Python version, but it seems to be a dirty practice.
Furthermore, I still don't understand why the result of a shell command sent by LC differs from the sale command sent in Terminal.

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 1:13 pm
by SparkOut
Sorry, I don't really have any ideas.

Re: Check if Python 3 installed?

Posted: Sun Mar 13, 2022 1:25 pm
by richmond62
Remove python 2.7 and things may work. 8)