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.
2 Answers 2
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.
Comments
Here is the process you can follow to run the Python on your Git Gash.
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.
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 inexport PATH="$PATH:/C/Users/ComputerName/AppData/Local/Programs/Python/Python37-32", as we told you to above.)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.
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.Check to make sure that worked by typing exit, relaunching git bash, and then typing
python --versionagain.
Apply above process inside your project folder so that you can use it on VScode.
pyinstead ofpythonwork? Second, is there aC:\Python27\python.exe, or, if not, why did you add/c/Pythonto yourPATH?python.exeactually is. If that's notC:\Python27, adding/c/Python27won't help. See this question if you have no idea where to find it.pylauncher 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".