• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 553
  • Last Modified:

python 2.7 full path

I have python 2.7 installed on a windows 7 machine (very new to python), when it comes to running scripts I cannot just enter python myscript.py or py myscript.py, I have to enter the full path to the exe i.e. c:\python27\python.exe myscript.py

is there anyway to configure python to remember the path so i can run scripts with just python or py from the command prompt?
4 Solutions
Dan CraciunIT ConsultantCommented:
It's not a python issue.
Go to Control Panel->System->Advanced system settings->Environment variables

Look for "Path" in the list, click on edit, add a ";" and the python path (c:\python27) at the end.

This will allow you to run python script.py at the command prompt.

Do you have multiple versions of python installed or only python 2.7

Normally under windows you should be able to just type

Open in new window

without the preceeding python.
Windows should have the file associations setup correctly so that this should work.

To verify just type following command on the cmd prompt.
assoc .py

Open in new window

the output should be

Open in new window

now you type
ftype Python.File

and you should see something like
Python.File="C:\Python27\python.exe" "%1" %*

Open in new window

However if you really wanted to add python.exe to your search path, then you have to add it to your environment. this can be useful especially if you want to run scriupts like pydoc, pip, easy_install, pylint

RightClick on MyComputer and click on 'properties'
then on advanced system settings
then on environment variables
if you have sufficient privileges search in the section system variables otherwise in the section uservariables for the environment variable PATH.

now edit it and append
to it.
now when opening a new cmd window
echo %PATH%

Open in new window

to verify that your path is correct
and type
where python

Open in new window

to see whether python.exe can be located.

I assume windows7 as OS. the where command does not exist on windows XP and the settings might be located on slightly different places for other windows versions
For Python 3.4 (but may be correct for your version as well) reinstall and pay attention to the option "Add python.exe to Path" on the "Customize Python 3.4.0" page.

Add to PATH option
Checked this with 2.7.6 - no, installer doesn't have this option, but on Vista Python is available from cmd.exe session both as `py` and `python`. It may happen that the problem in in Windows 7, but perhaps you need to choose "Install for all users" option at start. Vista doesn't have a choice to "Install just for me".
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

As far as I understand
py.exe is a new feature of python 3.
it's basically a python launcher, which parses the first line ( e.g. #!/usr/bin/env python3 ) and calls then the according python with a compatible version.

py.exe is located in C:\Windows\py.exe if you installed a python 3.x version
I can't find py.exe inside of 2.7.6 installer. Looks like PEP-397 Abstract paragraph should be updated with information how the launcher is shipped. http://legacy.python.org/dev/peps/pep-0397/
py.exe is part of a python 3 install and will be copied to C:\Windows\py.exe
This is the python launcher. as discussed in the PEP document mentioned by techtonic.

If you don't install python 3 but only python 2 you will not find py.exe

If you install python 2 and python 3, then the launcher be associated with the .py and the .pyw file suffixes and depending on the first line (shebang line) call the apropriate python executable
To add to gelonida's, the Python 3.x must be at least of 3.3. Without using the #! in the script, the highest Python 2.x will be called.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now