-2

I am windows 64bit user. I use python3 installed via Anaconda package. I am trying to run python script through command prompt and Git bash but I keep getting error while running .py file. Type of error

In command prompt:

"python" is not recognized as internal or external command, operable program, or batch file.

In Git Bash:

bash: python: command not found 

I added the path of python to the system variable in the environment variables. The path I added is:

C:\Users\krishna\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\C:\Python3\

I found the path by typing python in the cortana search bar and opened the location and copied it. Then I checked th path in cmd by typing PATH but it didnt return new added path (python). Same way I also added path of my script to the system variable.

I searched around but couldn't solve it. Please if anyone can suggest some solution. Thank you for your time.

Krishna
  • 1
  • 4
  • try `py`, don't ask me why it's different on windows. *rolls eyes* – Tadhg McDonald-Jensen Aug 12 '20 at 21:25
  • py gives me same error – Krishna Aug 12 '20 at 21:38
  • @TadhgMcDonald-Jensen - It kinda has to be. On other systems the shebang `#!/usr/bin/env python` lets you run an environment dependent python. But Windows uses file extension for .exe association and that is global to the user. If you use only 1 python and no virtual environments, then a single python.exe in the path will do. – tdelaney Aug 12 '20 at 22:01
  • @TadhgMcDonald-Jensen- I tried writing py instead of python or python3 but it didnt work. I also added the path of my python and python script locations to the system variable but it didnt work. After adding the paths when I checked the PATH in command line its not returning the added path. – Krishna Aug 12 '20 at 22:13
  • @tdelaney- I am using only one python. If I am not wrong you trying to say while adding path to the system variable I should try just writing python.exe? – Krishna Aug 12 '20 at 22:19
  • "*After adding the paths when I checked the PATH in command line its not returning the added path.*" You should [edit] this info into your question. How *exactly* did you update the system `PATH`? What *exact* path did you put and how did you check that it is not "*returning the added path*"? Did you add the correct Python (the one from Anaconda)? – Gino Mempin Aug 13 '20 at 00:32
  • @GinoMempin- I have edited my question adding information about how I added path to the syatem variale. – Krishna Aug 13 '20 at 09:44

2 Answers2

0

First you need to check have you added anaconda to your environment variable or not. If you have, skip this step.

Search 'environment' in cortana search box, you might get something like open environment variable and all, click on it. A dialog box will open, and around bottom you will see an option labled, "Environment Variables". Click on it.

Now in user variables you will see 'Path' Written there, click on it and select edit. Here select new, now you need add paths here, how to find python and conda path?

Very simple, open conda command prompt and enter where python, either you will get one path or two. I prefer adding both if there are 2. They will look like something like this "C:\Users"User name"\AppData\Local\Microsoft\WindowsApps" remember no forward slash after windowsApps folder (The folder in which exe file exist) C:\Users"Username"\anaconda3 Now you also need to add anaconda to path, for that just enter "Where anaconda" and enter the path in similar way. something like this, "C:\Users"Username"\anaconda3\Scripts"

Now you are done with setting up, but mind you using python completely directly is still not possible, since you installed it via anaconda. so enter "conda activate base" in cmd. it will enter the environment and you are ready to go.

I must mention, for some it even runs directly after adding to path, means no need for conda activate command. But again for some, I still have to figure out the problem.

Please tell me what can I improve, this is my very first answer here.

SerAkshat
  • 1
  • 3
0

In windows,

  1. Search for anaconda prompt and run that. It will be similar to command prompt.
  2. use cd to change your path to the folder containing file.
  3. then write python running.py there and you will be good to go.

Ps: activate your environment accordingly before running your file.

Mughees
  • 832
  • 7
  • 16