How to run the python scripts on mac from Windows PC (original) (raw)
April 28, 2025, 10:23am 1
I have scripts on mac, but how can i run those scripts from windows PC ?
I have created one virtual environement in mac, there i have the scripts.
I can be able to get mac using ssh, but how to run the scripts which are in virtual environement.
JamesParrott (James Parrott) April 28, 2025, 10:27am 2
Once you’re SSH’d in to a Linux machine, venv and python commands can be run as normal. Don’t macs allow that?
barry-scott (Barry Scott) April 28, 2025, 10:46am 3
After you ssh into the mac you run the scripts exactly the same way you do when using the macOS Terminal/iTerm.
KriVic (Krivic) April 28, 2025, 11:03am 4
Thanks for your reply
If i run python xxx.py(Actually script is in MAC) in command prompt of windows pc then i am getting error like python is not defined. actually my scripts are available in virtual environment of mac. How to access that environment ? through ssh i have connected the mac but not in virtual environment of mac. do i need to connect that virtual environment or please suggest some solution.
barry-scott (Barry Scott) April 28, 2025, 12:00pm 5
What is you want to do?
connect to the mac and run the script on the mac?
install the script on your windows PC and run it on the windows pc?
When working on the mac how do you run the your script that using the venv?
KriVic (Krivic) April 28, 2025, 1:07pm 6
Yes, i would like to connect with mac and run the scripts on mac from windows PC
I have connected to mac, but when i run, its throwing out error as python is not recognized.
same scripts are working in mac..
KriVic (Krivic) April 29, 2025, 8:23am 7
Hi,
I can be able to run the python script on mac from windows command prompt after installing the packages outside of virtual environment.
Now How i can enter the password using python to connect the mac using ssh, in the command prompt.
I tried the below command to connect the mac from windows,
os.system(“ssh macxxxx”) now how to add and enter the password ?
CAM-Gerlach (C.A.M. Gerlach) April 29, 2025, 10:27am 8
Installing packages outside a venv is Very Bad Idea, and there’s no reason for it here. You just need to be sure to correctly activate your venv first as appropriate for your platform.
Don’t ever use os.system
; subprocess
is better in essentially every meaningful respect.
If you want to use straight command line just pass the password in a file (-f filename
, relatively secure-ish) or on directly on the command line (-p password
, NOT SECURE).
However, for doing anything non-trivial or cross platform you’re better off using a Python SSH client like paramiko or similar.
c-rob (Chuck R.) April 29, 2025, 11:55am 9
On Windows we use Remote Desktop to connect to another computer. But doing so does not set up any paths, so I have a batch file to set up all my paths. Make sure all paths to Python are set up on the remote PC (which sounds like the Mac PC).
Then run your virtual environment on the remote PC.
barry-scott (Barry Scott) April 29, 2025, 3:47pm 10
The OP is using a macOS computer not Windows.
When I ssh into my mac the PATH is setup just as it is if I start the GUI terminal.
steve.dower (Steve Dower) April 30, 2025, 4:03pm 11
This likely means you haven’t installed Python on the Windows PC. Because Python is a script interpreter, it has to be installed on every machine you want to run it on (unlike a compiler, which you install once and compile your scripts into something that doesn’t require the compiler anymore).
There are a number of more advanced options here, but I suspect in your case you just need to install Python on the Windows PC.
RAPTOR7762 (RAPTOR7762) April 30, 2025, 4:11pm 12
@KriVic Did you tick the checkbox “Add Python to path” during installation? I you didn’t you have to get the interpreter from Microsoft Store
barry-scott (Barry Scott) April 30, 2025, 8:14pm 13
Of course you do not have to do this.
Just use the py
command in place of the python command.
CAM-Gerlach (C.A.M. Gerlach) May 1, 2025, 8:37am 14
Yeah, or re-run the installation with that option. Or add it to path manually. Or specify the full path to the executable. Or install it via any other method. Or…