How to run the python scripts on mac from Windows PC

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.

Once you’re SSH’d in to a Linux machine, venv and python commands can be run as normal. Don’t macs allow that?

After you ssh into the mac you run the scripts exactly the same way you do when using the macOS Terminal/iTerm.

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.

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?

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..

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 ?

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.

1 Like

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.

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.

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.

@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

Of course you do not have to do this.

Just use the py command in place of the python command.

2 Likes

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…