bash: 'command not found' for python, r and nano - python

On git bash, I receive a command not found message for python, r and nano.
I am on Windows 10. I do not know what I am doing wrong.
I type
r --version
python --version
nano --version
and they all return command not found.
I read something that had me try
alias python='winpty python.exe'
and it renamed python, but when I tried
touch .bashrc
it returned
touch: command not found
I followed the instructions in a Github course, PS239T. I have been fortunate, except for getting these three programs to work.
I tried
build/console.exe c:/Python36/python.exe
and it returned
build/console.exe: No such file or directory
I tried
PATH=$PATH:/c/Python36/
$ export PATH="$PATH:/c/Python36"
echo 'export PATH="$PATH:/c/Python36"' > .profile
and nothing.
I got Python 64-bit via Anaconda.
I tried setting up the Python 3.4 environment
conda create –n py34 python=3.4 anaconda
./python name_of_your_python_script.py
nothing.
which python
got me a huge directory path:
which: no python in (/c/Users/Edward/bin:/mingw64/bin:/usr/local/bin:usr
/bin:/bin:/mingw64/bin:/usr/bin:c/user/Edward/bin:/c/Program Files
(X86)/Intel/ 1CLS client:/c/Program Files/Intel/1CLS Client:/c/Windows
/System32:/C/Windows:/C/Windows/Sytem32/Wbem:/c/Windows/System32
WindowsPowerShell/V1.0:/c/Program Files/Intel/Intel(R) Management Engine
Components/Dal:/c/Program Files/Intel/Intel(R) Management Engine
Components/IPT:/c/Program Files (x86)/Intel/Intel(R) magament Engine
Components/IPT:/c/Program Files (X86)/Intel/Intel(R) Management Engine
Components/IPT:/c/WINDOWS/Syste,32/Wbem:/c/WINDOWS/System32
/WindowsPowerShell/v1.0:/c/Program Files (x86)/Rand McNally/RNDDock
/GtkSharp/2.12/bin/:/c/Program Files d/AppData/Local/Mircosoft
/WindowsApps:/c/Users/Edward/AppData/Local/Pandoc:/usr/bin/vendor_perl:
/usr/bincore_perl:/c/python36
I would have just put up the screenshot or copied and pasted it, but I do not know how.
I am sure I made an error somewhere.
I get the same type of results when I try to figure out what is going on with r and nano.
Update 1
Download and install 'Anaconda'
'https://store.continuum.io/cshop/anaconda/'.
Download the default Python 3 installer 'do not follow the link to version 2'.
Use all of the defaults for installation except make sure to check 'Make Anaconda the default Python.'
Install R by downloading and running
'this .exe file from CRAN'
'http://cran.r-project.org/bin/windows/base/release.htm'.
Also, please install the 'RStudio IDE'
'http://www.rstudio.com/ide/download/desktop'.
All you need is RStudio Desktop.
nano is a basic editor and the default that we use in this class. To install
it, download the Software Carpentry Windows installer
http://files.software-carpentry.org/SWCarpentryInstaller.exe'
and double click on the file to run it. 'This installer requires an active internet connection.'
Sublime Text is a more advanced editor. Download Sublime Text 3 'here'
'https://www.sublimetext.com/3'.
Update 2
I began trying janos advice and ran
/c/Python36/python.exe --version
and it returned
bash: '/c/python36/python.exe: No such file or directory.
I tried to run
PATH="/c/Python36:$PATH" python.exe --version
but it returned
bash: python.exe.: command not found
I tried to run
PATH="/c/Python36:$PATH" python --version
and it returned
bash: python: command not found
Update 3
janos told me I went too far without figuring out the problem, then told me to run
ls -l /c/Python36/python.exe
and it returned
ls: cannot access '/c/Python36/python.exe': no such file or directory.
janos told me to focus on the first error
bash: '/c/python36/python.exe: No such file or directory.
after entering
/c/Python36/python.exe --version
and so there I will focus.
janos asserted
Can you open a file explorer and navigate to C:\Python36, and see python.exe there? Probably not.
and is correct.
I ran
C/Users/Edward/Anaconda3/pkgs/python-3.6.3-h9e2ca53_1/python.exe
with no success.
I ran that in explorer and found that the publisher could not be verified.
Update 4
I went to
'python.org/downloads/release/python-363'
and downloaded 'Windows x86 embeddable zip file' and Unzipped it in
C/Users/Edward/Anaconda3/pkgs
it worked.
Thank you.
I bet I am having the same problems with 'r' and 'nano'.
I am going to run down the list again and perform all the check. I will do the same thing with 'r' and 'nano'.
Everything worked out for Python. I will do 'nano' and 'r' in due course.
I could not find
/c/python36/
so I used
/c/Users/Edward/Anaconda3/pkgs/python-3.6.3-embed-win32/
Update 5
janos is right again. I would need to create the python36 folder as it was not built automatically during the installation. janos' method worked on 'r' and 'subl' or sublime text 3. I gave up on 'nano'.
I found that some of my '.exe' files were in listing with spaces in the names. I moved to the user folder and eliminated any spaces.
I also downloaded version from the official website, and that too helped.
I could not figure out how to get 'nano' to work. I could not even find it on my pc. I used 'subl' instead.

Start from the basics. Try the simplest thing that can possibly work,
and make progress in baby steps,
from one sane state to the next.
The first step is to run a by entering its absolute path directly.
If the Python executable is at /c/Python36/python.exe, then run this:
/c/Python36/python.exe --version
This is very simple and it should just work.
If it doesn't, the command will give you an error message with clues.
A next step could be to simulate adding to PATH. Try this:
PATH="/c/Python36:$PATH" python.exe --version
This is one line. It sets a value to PATH in a way such that it's only active during the execution of the command. After the command completes, the value of PATH will be back to what it was before. This is a good way to test things. Also notice that I prepended to PATH the directory that contains python.exe, not the full path to python.exe.
That's an important point, this is how the PATH variable works.
It's a list of directories, and all executable files in those directories become easily executable by simply typing their name, without having to type their absolute paths.
Next, I would try this:
PATH="/c/Python36:$PATH" python --version
That is, see if you can drop the .exe from the name of the command.
I don't have Windows so I cannot test if this works.
And maybe it doesn't. (But I think it does.)
If everything worked so far, then the next step is to make the PATH setting permanent.
The way to do that is to put the command PATH="/c/Python36:$PATH" into a file that is always executed when you start a new Git Bash session.
If I remember correctly on Windows you can put it in ~/.profile
(a file named .profile in your home directory).
Where is ~? Here's one way to find it:
cd
explorer .
The above opens a file manager inside that directory.
You can use a plain-text editor like Notepad or Wordpad to edit it.
You can also use this shell command to append the line that updates PATH:
echo 'PATH="/c/Python36:$PATH"' >> ~/.profile
This line will get executed in all new Git Bash session.
Not in the current session,
because this file is only executed once.
If everything above worked, then in a new Git Bash session you should be able to run python --version.
If not everything worked, then you need to read the error message you get carefully, and not advance to the next step until the problem is resolved.
It's useless to advance to a next step when you are already not in a sane state.
You can follow the exact same logical process for all the other programs too.

Related

Python isnt recognized in cmd and i cant use pip

im pretty new to coding and stuff but for whatever reason, python, pip or even doing cd C:\Python38\scripts cmd will just tell me the directory isnt found or that it isnt a command, i did echo %PATH% and it is in there. (this is probably a really simple solution, im not advanced with stuff like this at all)
Open a new CMD with the start menu
go to the location where python is installed.
press on the Path next to Search Bar.
Copy, back to CMD, cd (paste)
This will set the working directory to where python is installed.
You can test now with python command, and check it it works , then the issue is only path related.
Now for checking with Path, You will need to add the complete path to the python.exe the one you just copied into CMD.
For example
C:\Users\George\AppData\Local\Programs\Python\Python39 at this path there will be a python.exe where You can execute with CMD.
If you have an issue with the path and have to update to the new one, Make sure to start a new CMD window to take the effects of the Path update.
You would need to add python in the PATH variable to access python from cmd in windows.
Please see the article at this link Adding python to Path
Post that you would be able to access pip from cmd/ use pip within cmd

Run Python script with Automator // why does it only work if I include export PATH=/usr/local/bin:$PATH and what does it mean?

I was trying to run a Python script via Mac's Automator and the command is very straight forward:
"cd /Users/myname/Desktop/project && python3 myprojectapp.py".
However, every time I tried to run it, Automator raised an error such as ModuleNotFoundError. This was however, impossible since I had all libraries (e.g. Pandas) installed and running the command in the Terminal as written above worked flawlessly.
Now, I've read somewhere for a similar problem to just include:
"export PATH=/usr/local/bin:$PATH" before the command and it worked. Now, before I go on with my life, I would like to understand what exactly this extra line does and how it affects Automator to the point of making the script work.
Thank you in advance!
That command basically modifies the environment variable PATH and puts the directory /usr/local/bin before everything that is currently in PATH. However, that command is temporary, and the environment variable PATH is restored when the session closes.
What could be happening is the python you're running in terminal and the python Automator is running are different./usr/local/bin probably contains the same python version as you are using in terminal. Take a look at ~/.bash_profile to see if something similar to export PATH=/usr/local/bin:$PATH is in there.
Another way to check is to type which python in both and see if it points to the same python. You probably have yet another python somewhere in the list of directories in your PATH variable.
It's common to use virtual python environments to keep track of which python is running and to experiment with python without messing with system python. Examples of these include: Anaconda and virtualenv.

SCons does not seem to install (Windows)

I have been trying for hours to install SCons on my Windows 8.1 machine and simply cannot. I honestly have no idea whatsoever what I'm doing wrong, or really what I'm doing in general. Here is the step by step process of what I have done
1: installed Python 3.7 from www.python.org I used the python-3.7.3-amd64.exe to install it, it seems to have worked (I have never used python before so if anything is off I wouldn't realize it). When I use the command console and input 'python --version' it outputs 'Python 3.7.3'
2: I downloaded scons-3.0.5.zip from www.scons.org I followed the website's instructions as best I could. I used 7zip to extract it's contents into a new file called 'scons-3.0.5' located at C:\ It's complete path, therefore, is C:\scons-3.0.5
3: I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5' just as the scons website says to do. It outputted nothing, and I noticed that the new line started with '...' instead of '>>>', I have no previous experience with Python so I don't know if that's good or bad. I then continued to follow the instructions by inputting '# python setup.py install', it outputted nothing, and once more the new line started with '...'. I hoped that was all I needed to do but in the command console I inputted 'scons --version' (I read somewhere this can be done to check if it is installed), it outputs "'scons' is not recognized as an internal or external command, operable program, or batch file.". This, combined with the fact that seemingly nothing is different, leads me to believe it has not been installed.
4: I tried to do something a bit different. I noticed that the zipped file I downloaded from the scons website contained 2 files in it, 1 being scons-3.0.5, the other being pywin32-master.zip, I had both of these in the file C:\scons-3.0.5 I decided to delete that file, and in its same location place the scons-3.0.5 file. Now instead of C:\scons-3.0.5 including scons-3.0.5 and pywin32-master.zip it contained just the contents of the scons-3.0.5 file that was in it before (if that makes sense, I might clean it up in the morning and make it easier to read). I once more did step 3, and the results were no different.
I have no idea what I'm doing, I have no prior experience with Python or the command console, I just want to set up scons and never use Python again. Does anyone know how I can fix this? I have googled for hours but it seems as if I'm the only one who's having this issue.
The contents of the zipped file from scons website:
contents of the scons-3.0.5 file in the zipped file
I doubt the images will help but I have included them just in case if they seem off
edit: I did know what installing via Pip was, but I googled it and it worked just fine! Thanks to Alexander Lopatin and bdbaddog for the help
So you're mistake is in step 3.
I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5'
The website says:
# cd scons-3.0.5
# python setup.py install
Notice this is
cd into the unzipped directory
THEN run python setup.py install
Instead you've run python, then typed a shell command into python. Which is why you had issues.
Note: On windows you shouldn't need to run as admin to install SCons.
Although as #dirkbaechle said. Pip is the preferred method to install python.
python -mpip install scons
But if you'd rather follow the instructions. Just bring up a windows command shell, or powershell if you like, cd into the unzipped directory, and run python setup.py install
BTW. There's an IRC channel and a users mailing list for SCons support.
https://scons.org/contact.html

Command Prompt: Set up for Python 2.7 by default

My command prompt is currently running Python 3.2 by default how do I set it up to run Python 2.7 by default, I have changed the PATH variable to point towards Python 2.7, but that did not work.
UPDATE:
It still does not work. :(
Still running python3 - to be specific it runs python3 when I am trying to install flask - which is what I want to do.
More generally, when I simply type python into the command line, it does nothing.
I get a 'python' is not recognized as an internal or external command, operable program, or batch file error.
No idea what to do.
If you call your Python scripts directly using python script.py then setting the PATH to have the 2.7 directory first should be enough.
If you want to call Python scripts indirectly with the shell, i.e. by writing just script.py or by executing the file from the explorer, you need to set the 2.7 installation as the default program handler for the .py extension. The easiest way to do that is to run the Python installer again and choose the option “make this installation the default”.
Note that with the new launcher, that ships with 3.3+, you don’t need this, as you can specify the version number using a shebang line and the launcher will automatically pick the appropriate interpreter.
Changing your PATH environment variable should do the trick. Some troubleshooting tips:
Make sure you didn't just change the local, but rather the system variable to reflect the new location
Make sure you restarted your CL window (aka close "cmd" or command prompt and reopen it). This will refresh the system variables you just updated.
Make sure you remove all references to C:\Python32\ or whatever the old path was (again, check local and system PATH - they are both found on the same environmental variables window).
Check to see if Python3.2 is installed where you think it is... (just rename the directory to something like OLD_Python3.2 and go to your CLI and enter "python" - does it start up? If it does is it 2.7? or 3.2? If not, you did something wrong with your PATH variable.
All else fails - reboot and try again (you might have some persistent environment variable - which I don't see how that can be - but hey, we are brainstorming here! - and a reboot would give you a fresh start.
If that doesn't work then I'd think you are doing something else wrong (aka user error). CMD has to know where to look for python before it can execute. It knows this from your PATH variable... now granted, I work almost exclusively in 2.6/2.7, so if they did something to the registry (which I doubt) then I wouldn't know about that.
Good luck!
Change the two las lines to you current python desired build path:
Windows Registry Editor Version 5.00
' Extracted from Python 2.7 silent installation By Elektro H#cker
[HKEY_CLASSES_ROOT\.py]
#="Python.File"
[HKEY_CLASSES_ROOT\.pyc]
#="Python.CompiledFile"
[HKEY_CLASSES_ROOT\.pyo]
#="Python.CompiledFile"
[HKEY_CLASSES_ROOT\.pyw]
#="Python.NoConFile"
[HKEY_CLASSES_ROOT\Python.File\Shell\Open\Command]
#="CMD /K \"\"C:\\Program Files (x86)\\Python\\Python.exe\" \"%1\" %*\""
[HKEY_CLASSES_ROOT\Python.NoConFile\Shell\open\command]
#="CMD /K \"\"C:\\Program Files (x86)\\Python\\Pythonw.exe\" \"%1\" %*\""
Could you try this as root:
$ ln -s python2.7 /usr/local/bin/python
Logout & login again as root:
$ python -V
It works for me, hoping the same to you.
Cheers,

/bin/env: python: No such file or directory (Windows through Git Bash trying to install new Parse Cloud Code)

Trying to install python from the link here does not seem to give access to the python command in Msysgit... following the instructions here, does not actually say how to get python to work as needed.
Current error when running parse new project_name is:
/bin/env: python: No such file or directory
I believe it's likely because it installed it at C:\Python... anyone know how to fix this?
This error means that Git Bash does not know where your python.exe is. It searches your normal windows search path, the PATH environment variable. You're probably failing the 4th step on the instructions already "Make sure Python is working in the Git Bash":
$ python --version
sh.exe: python: command not found
To fix that, append C:\Python (or wherever you installed python) to your PATH environment variable in windows (instructions here). You need to restart the bash after this for the change to take effect. This will allow you to run python from the windows command prompt as well.
C:\> python --version
Python 2.7.2
If you don't want to alter your windows PATH variable or make python only available to git bash, you could create a .bashrc file in your %USERPROFILE% directory and set the variable there:
C:\>notepad %USERPROFILE%\.bashrc
and add
export PATH=/c/Python:$PATH
to the file. That script is executed every time you start the git bash and prepends C:\Python to git bash's PATH variable, leaving the system-wide PATH variable untouched.
Now that you know what has to be done, you can use this shortcut on the bash instead (appends the export command to your .bashrc)
$ echo export PATH=/c/Python:\$PATH >> ~/.bashrc
Hmmm. If you're using Python 2.7 like the instructions say to, you could try instead of that doing "C:/Python27/python.exe" insted of "python".
I think you can add the location of the python.exe in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';' (without quotes) and then add the absolute path of the .exe file which you want to run via Git-Bash.
don't know if this could be your issue, but its always worth a check.
check your python path is set correctly?
computer->properties->advanced system settings-> environment variables->system variables->PYTHONPATH, value = C:\PYTHON20;C:\PYTHON20\DLLS;C:\PYTHON20\LIB;C:\PY THON20\LIB\LIB-TK

Categories

Resources