Check if Python 3 installed?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 10:24 am

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Check if Python 3 installed?

Post by richmond62 » Sun Mar 13, 2022 11:00 am

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 4049 times

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 11:17 am

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Check if Python 3 installed?

Post by richmond62 » Sun Mar 13, 2022 11:26 am

This:

Code: Select all

on mouseUp
   put shell ("which python3")
end mouseUp
gave me: /usr/bin/python3
Last edited by richmond62 on Sun Mar 13, 2022 11:44 am, edited 4 times in total.

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 11:32 am

Sorry, forget "console", it's Terminal.

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Check if Python 3 installed?

Post by richmond62 » Sun Mar 13, 2022 11:42 am

Sorry, forget "console", it's Terminal.
Ce n'est pas un problem, c'etait un problem avec mon cerveau . . . 8)

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 11:43 am

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 ;)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Check if Python 3 installed?

Post by richmond62 » Sun Mar 13, 2022 11:44 am

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

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Check if Python 3 installed?

Post by SparkOut » 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.

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 12:02 pm

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
:(

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 12:06 pm

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.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Check if Python 3 installed?

Post by SparkOut » Sun Mar 13, 2022 12:10 pm

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

Zax
Posts: 469
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Check if Python 3 installed?

Post by Zax » Sun Mar 13, 2022 12:58 pm

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.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Check if Python 3 installed?

Post by SparkOut » Sun Mar 13, 2022 1:13 pm

Sorry, I don't really have any ideas.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9386
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Check if Python 3 installed?

Post by richmond62 » Sun Mar 13, 2022 1:25 pm

Remove python 2.7 and things may work. 8)

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”