Some commands not working in Command Prompt - python

I am using command prompt to run CUDA on windows. When i open cmd, the current directory is pointed towards home folder. When i type nvcc, output is nvcc : fatal error : No input files specified. It means i can run nvcc with a file. But, when i type python, it shows
'python' is not recognized as an internal or external command,
operable program or batch file.
I need to change my directory to run python.
My question is, how to make python run without changing the directory? Is it like inputting cmd about change in the library path as in ubuntu?

Windows, like Ubuntu, has the concept of a "path", which is a list of directories that the shell will search to try to find the command you typed. Therefore, the nvcc command is probably located in a directory found in your system's path, but the python command is not.
Therefore, you'll need to find where on your system the python command is, and put that command's directory into the path. So, if python is located at C:\Python26\python.exe, you will need to add C:\Python26 into the path.
Superuser has some answers that can describe how to modify the path in windows, or otherwise you can google how to do this. The exact steps may be different depending on the version of Windows that you have.
Additionally, you can also ignore the path and run the python command using the full filename. Instead of typing python, you would type (using the above example) C:\Python26\python. This would have the same effect, although would be a bit more typing.

Related

How do I run the python files from command shell/command prompt?

Really frustrated with this as one thing works at one time. Sometimes import filename.py works. But in the tutorials all I see is python filename.py. But when I try to give that, I am facing an error like invalid syntax.
I have edited all the environment variables and I have C:\Python27 folder in the same location. To be able to run the files using python filename.py what are the conditions that must be met? What should be the current working directory? Should the .py files be there in the same working directory?
import name is a python keyword for use within a python script and/or the python interactive interpreter (repl).
python filename.py is a shell command for use at a command prompt or within a shell script to run the python interpreter on a given python script file.
The working directory does not matter other than for whether the file listed in python filename.py can be found.
So for python filename.py to work you must be in the same directory as filename.py but you could just as readily use python c:\users\user\some\other\path\filename.py in which case the current directory isn't used to find the file.
If you get python syntax errors from attempting to run python on a python file that's a python error in the code and you will need to look at the python file to see what the error is.
Just to be clear, typing python filename.py only works from the Terminal (i.e. cmd.exe, Windows PowerShell, the "Terminal" application on a Linux kernel, etc.), not from the Python interpreter (i.e. python.exe), and only works if you have used the cd command to change into the directory in which the file is saved (so that the terminal knows where to look for filename.py). import filename can be used from the Python interpreter, but is not the ideal method as it creates a compiled version of filename.py and can only be used once (you would have to restart the interpreter to do so again). I'm not sure whether this works in the official Python distribution available from the Python website, but at least in the Anaconda distribution, you can run a file from the Python interpreter using runfile("C:/Users/CurrentUser/Subfolder/filename.py").

How to run an executable on Cygwin

Say I want to run an executable with a filename argument that is within my working directory, in Windows cmd I would go:
C:\Python27\python signalme.py
How can I do so in Cygwin? NOTE: C:\Python27\python is an executable. Please give me a full answer, I read somewhere here that you should add a .\a, but I couldn't know where to add it.
Cygwin attempts to make a Linux-like user environment available on Windows. To run a executable file on a Linux-like command line, you need the following things:
You have to be able to find the executable, which means one of the following:
The executable is in a directory that is included in your PATH environment variable.
You know the explicit absolute path to the executable, which you can specify at the command line
You know the relative path from the current directory to the executable, which you can specify at the command line.
The file has to have the executable permission set for the user you're attempting to use to run that file.
So, to run an executable in your working directory, you can specify the relative path to the working directory, along with the filename: ./foo.exe.
In your case, you want to use the Python interpreter to run a local Python file. You will most likely need to use the Cygwin-installed Python. That Python will probably be in your PATH, so just run:
python signalme.py
This could fail, with an error message like bash: python: command not found - in which case you should re-run your Cygwin setup, look for the opportunity to install Python, and make sure you install it.
/cygdrive/c/python27/python.exe signalme.py

Run a python script in windows

I have always used a mac to write and run python scripts. However, I have a bunch of files on a PC that I need to run a script on. I have never really used a PC and don't know how to run the script.
If I go to the command program on the PC and type in python, nothing happens. How do I find where the python path is in order to get into the python prompt? Also, once I am in the prompt, is the importing of modules the same as in a Unix system?
Python isn't added to the system environment's PATH variable by default on windows. You have to either add the path to the directory containing the Python.exe file to the PATH variable, or call python explicitly.
This issue has been addressed in the Python documentation:
Python Documentation: # How to run a Python program under windows
Assuming Python is installed, it is usually placed in a folder prefixed with "Python" and the major/minor version. E.g. C:\Python26

Installing python 2.7.2 on Debian 5.0

I'm having some trouble running the ./make command in my debian command line to install python 2.7.2.
I untarred my download from Python.org and ran ./configure which appeared to have worked fine. Unfortunately when I type in ./make I get the following error:
./make: No such file or directory
Not sure why this occurs, but I'd like to get an updated version of python to continue learning the language.
Thanks for your help,
Andy
When you type ./configure, it runs a executable script in the current directory (labeled with a .) called configure.
Make is an executable file, usually located somewhere like /usr/bin, which uses a file in the directory to run a bunch of commands depending on whether files are up to date.
When you just type make, your shell (the program that handles all your commands and sends their output to the terminal) will go looking through all the directories in the PATH environment variable to find an executable file called make, and run the first one it finds. But, when you type ./make, you're actually telling it to try and run an executable file in the current directory, called make. (It uses this approach, not searching the PATH variable, whenever you put a / in the command.)
You can use the . anywhere you could use a normal directory to specify the same directory, so for example: /usr/bin/././././ is the same as: /usr/bin. Similarly, you can use .. to specify the directory above, so /usr/bin/../bin/../bin/../lib is the same as /usr/lib.
So, after running the configure script located in ./, which generates a so-called makefile, you run the system wide version of make, located where ever, by just typing make, which uses the makefile to build the package.
Also, you can use the which command to find out where the command that'll run when you enter a command by itself - for example, which make.
(Apologies if any of this is condescending, I was going for completism. Also, I may have overused the code tags...)
its not ./make
try
"make"
as it is

How can I get python in the command prompt on Windows?

I have just installed Python on my Windows 7. I thought that after that I will be able to run python on the command prompt but it is not the case. After the installation I also found out that I can run the python command shell. This is nice. But what should I do if I want to save my program in a file and then I want to run this program (in Linux, for example, I typed "python file_name.py" in the command line).
You need to add the python bin directory to your path. Follow the instructions here and add c:\python26\bin to the path (unless you installed python in a non-default location).
Is python.exe in your windows path? Try to look at the PATH environment variable and see if the installation folder of python is listed there.
You need to update your environment variables to include the path to the Python executable.
On XP you can do this by right clicking on "My Computer" -> Properties and then going to the "Advanced" tab.

Categories