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:
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):
-
-
and so did this:
-

- 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:
--> /bin/sh: line 1: python3: command not found
--> [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:
Python 3:
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 . . .

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 . . .
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
-
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:
--> Python 2.7.10
From LC:
--> Python 2.7.10
From Terminal:
--> Python 3.7.8rc1
From LC:
--> /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
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
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.
