-2

i was making a program for command line and it was very easy to make it a command in other operation systems. but i tried to make another version of that program in windows. i turned the script into a .exe file using pyinstaller and then i searched for making it a command so i can run it from windows command prompt but the only way that i found was to move the script to system32 folder. i have config files and also it doesn't make sense to put a script in system32.

is there any other way to do that?

DiVeRsO
  • 3
  • 1
  • 3
    Does this answer your question? [How can I convert a .py to .exe for Python?](https://stackoverflow.com/questions/41570359/how-can-i-convert-a-py-to-exe-for-python) – user_na Jun 24 '21 at 16:36
  • 1
    Q: How do I run a Python script in Windows, without installing Python? A: You have several options, including using pyinstaller to convert the script into a self-contained .exe: https://stackoverflow.com/a/41574646/421195. Q: How do I get any arbitrary script or .exe to run without specifying the full path name? A: Update the Windows %PATH% – paulsm4 Jun 24 '21 at 17:03

2 Answers2

1

If I understand correctly, I think that you could create a folder for your custom commands and add it to the PATH environment variable on Windows, that way, you could just open cmd, call the command and it will be recognized and executed.

sagape4
  • 26
  • 4
  • yes but how can i add a folder to PATH environment variable? – DiVeRsO Jun 24 '21 at 17:02
  • Control Panel\System and Security\System, there, on the left pane, select "Advanced system settings" and in the window that opened, select Environment Variables. There, double click on "PATH" (it could be all capital or like "Path") and you'll see all the folders already added, just add yours and that should do it. – sagape4 Jun 24 '21 at 17:09
0

To run your script from the command line outside of the directory that the script is in, your command line needs to know where your script is.

One of the places the command line will look is in system32, which is why someone told you to put it there.

You can update your environment PATH to point to the location of the python script to do what you want to do.

user3328152
  • 95
  • 1
  • 7