2

I just entered a class as an introduction to Python, and so I downloaded GitBash and Andaconda on my Windows laptop. I navigated to my python file on GitBash and tried to execute my python file, to no avail. I searched this website for answers on what to do and tried as many solutions as I could find, but I had no luck. I am quite a noob at this, so I think I am missing something obvious. Perhaps just one line of code that could save me?

...

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ ls
python_intro.py

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python python_intro.py
bash: python: command not found

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ PATH=$PATH:/c/Python27/

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python python_intro.py
bash: python: command not found

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ export PATH="$PATH:/c/Python27"

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python python_intro.py
bash: python: command not found

TECH-TESTER+usd@Tech-tester MINGW64 ~/Desktop/Python-Essentials/PythonIntro
$ python
bash: python: command not found

Sorry if this is such a rookie question, it just seems that everything I find on the internet is above my level to understand, whereas I am at this very basic level.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • First, does `py` instead of `python` work? Second, is there a `C:\Python27\python.exe`, or, if not, why did you add `/c/Python` to your `PATH`? – abarnert Aug 17 '18 at 00:43
  • py did not seem to work. Secondly, the only reason I added the part with Python27\python.exe is because it was suggested on another question that looked similar to mine, but I really have no idea what it means or does.. – Tyler Mansfield Aug 17 '18 at 00:51
  • OK, what you need to do is to add the path to wherever `python.exe` actually is. If that's not `C:\Python27`, adding `/c/Python27` won't help. See [this question](https://stackoverflow.com/questions/37117571/) if you have no idea where to find it. – abarnert Aug 17 '18 at 00:58
  • Meanwhile, I _thought_ Anaconda came with the same `py` launcher as "official" Python, and offered the same option to install it to somewhere on your PATH. I could be wrong (I don't use Windows very often…), but you might want to try going through the installer again to see if there's a checkbox you should have enabled but instead disabled that says something like "Install Python Launcher on system PATH". – abarnert Aug 17 '18 at 01:00
  • For another possible solution: do you actually _need_ to use bash here? If you aren't going to be doing anything too fancy with the command line, just running Python scripts and starting the Python interpreter, you may be better off just using the "Anaconda Prompt" (which is the usual Windows command prompt, but all set up to run Anaconda), or even using the shell inside a GUI like Spyder. Or, if you just can't handle the Windows prompt and need a decent shell, maybe run a Linux VM/container/userbox/whatever, and install Anaconda for Linux inside that VM. – abarnert Aug 17 '18 at 01:02
  • My guess is that you've not installed python. Try installing python, typically from www.python.org – Chai Ang Aug 17 '18 at 05:14
  • Okay, so I found where python.exe is, its at: C:\Users\usd\Anaconda3. So what exactly should I type to direct Python to that file? I tried: `$ export PATH="$PATH:\C\Users\usd\Anaconda3"`, but that didn't work: the following line still had the same python error where it said "bash: python: command not found" – Tyler Mansfield Aug 20 '18 at 21:18

2 Answers2

1

Meanwhile, I thought Anaconda came with the same py launcher as "official" Python, and offered the same option to install it to somewhere on your PATH.

Try first to check that in a regular CMD.

where python

That will check if python is in the PATH or not.
From there, you can start using python, in a CMD or a git bash session.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Here is the process you can follow to run the Python on your Git Gash.

  1. Launch the program Git Bash in the usual way that you launch Windows programs or VScode. A shortcut for Git Bash was created during installation.

  2. At the command prompt, paste this command export PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32". That will tell Windows where to find Python. (This assumes that you installed it in export PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32", as we told you to above.)

  3. Check to make sure that this worked correctly by entering the command python --version. It should say Python 2.7.8 (or 2.7.something), as shown in the figure below.

  4. Assuming that worked correctly, you will want to set up git bash so that it always knows where to find python. To do that, enter the following command: echo 'export PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32"' > .bashrc. That will save the command into a file called .bashrc. It will be executed every time git bash launches, so you won’t have to manually tell the shell where to find python again.

  5. Check to make sure that worked by typing exit, relaunching git bash, and then typing python --version again.

Apply above process inside your project folder so that you can use it on VScode.

Fahim
  • 19
  • 1
  • 5