I\'m trying to learn python but have some problem running source files from power shell. When I type \'python\' it opens up and I can type python commands directly in the sh
You might have more than one version of Python installed and the version IDLE is using is newer. To see what version of python you have you can type >python -V
at a command line. If that version looks appropriate then you might need the full path to the file as the second parameter. E.g >python C:\myfile.py
.
If you installed Python correctly there is always a chance that just typing the name of the script will run it with python. E.g. >myfile.py
I always find that adding C:\Python27
to the %PATH%
variable and .PY
to the %PATHEXT%
variable makes running scripts easier. In this case just >myfile
should work.
Edit after Update:
Typing just >python
with no parameters opens python in 'interactive mode' which is different from the batch or scripting mode that your script is intended for. If executed with arguments the first argument is taken as the file path and further arguments are passed to the script in the sys.argv
list.
Try to type this in Powershell:
$env:path="$env:Path;C:\Python33
After this, command
python yourfile.py
should work.
Disclaimer: I don't know PowerShell, but I do know cmd.exe.
I don't know why python myfile.py
doesn't work, but assuming that PowerShell bears at least some similarity to cmd.exe, the following should probably work: myfile.py
. That's right, just enter the name of the Python script and hit enter.
This my sound silly, especially coming from a beginner.
Just save the file on your desktop. Open up powershell and drag the file directly into powershell and it opens. kind of tedious but it works
If you started by typing "python
" in powershell
you will need to get out of that script.
If you are in python type:
quit()
then type
python myfile.py
This should work if your python is installed correctly.
You will need to put the full path of the Python executable within the command line in order for it to work. You could check and ensure that your python exe is included in your Path among your system variables.