Reputation: 11
Yes, I've searched. So after spending about 4-5 hours struggling just to get Python files running, I recently stumbled over the solution to get it running through the environment variables like this: cmd -> python -> Python starts, yay yay
Since it didn't work to do it through the command line and similar I had to do it manually through the Windows interface. Now that it's working, however I cannot open .py files without typing out the full path like this: python C:\X\X\X\test.py which is obviously also starting to get annoying.
So now I'm trying to find out which variable I have to change (yet again) to only be able to type 'python test.py' and have it running. Sorry if I come off vague, but it's always a major pain to setup a new programming language for me and it kills my mood.
Thanks for help, it'll be really appreciated.
Upvotes: 1
Views: 743
Reputation: 9163
To make python
executable on your command line, you need to add it to your PATH
environment variable, which it sounds like you have done on the command line. It is quite simple to add directories to the PATH
in Windows if you know where to look. Essentially, you need to get to the Environment Variables
dialog box, which is slightly different for each version of Windows.
For Windows XP:
Start -> Control Panel -> System -> Advanced -> Environment Variables
For Windows Vista, 7: Click the Start Orb, right-click
Computer
and selectProperties -> Advanced -> Environment Variables
Then, in the lower of the two boxes, find Path
and click Edit
. Change it so that C:\Python27
(or whichever version of Python you have) is at one end of the list, separated from the other entries by a semicolon (e.g. C:\Python27;C:\Program Files ...
)
Once you've done this, python
will work at the command line whenever you open a command window.
Regarding your second issue, however, there isn't much you can do. You must either specify the complete path to your script or already be in the same directory as the script. That is, if the script is in C:\X\X\X
you will either need to invoke it as C:\X\X\X\test.py
or first cd C:\X\X\X
.
Upvotes: 2
Reputation: 993105
When you say
able to type 'python test.py'
I'm not sure exactly what you mean. Normally when the Python interpreter runs, it looks in the current directory for any source file that is named on the command line (unless you specifically name a location for the source file, as you've discovered). It seems from your previous statement:
python C:\X\X\X\test.py which is obviously also starting to get annoying
that your test.py
file exists somewhere else.
What you might want to try is to change the current directory first, before running your script. In a command prompt window, type:
C:
cd \X\X\X
python test.py
(obviously substituting your actual path name). My apologies if you already know this.
Upvotes: 2