Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

python 2.7 full path

Posted on 2014-03-19
7
Medium Priority
?
548 Views
Last Modified: 2014-03-24
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?
0
Comment
Question by:pma111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39939460
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.

HTH,
Dan
0
 
LVL 17

Assisted Solution

by:gelonida
gelonida earned 500 total points
ID: 39939476
Do you have multiple versions of python installed or only python 2.7


Normally under windows you should be able to just type
myscript.py

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
.py=Python.File

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
;C:\Python27;C:\Python27\Scripts
to it.
now when opening a new cmd window
type
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
0
 
LVL 9

Assisted Solution

by:techtonik
techtonik earned 500 total points
ID: 39939489
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".
0
Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
LVL 17

Expert Comment

by:gelonida
ID: 39939624
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
0
 
LVL 9

Expert Comment

by:techtonik
ID: 39939854
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/
0
 
LVL 17

Expert Comment

by:gelonida
ID: 39939862
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
0
 
LVL 29

Assisted Solution

by:pepr
pepr earned 500 total points
ID: 39947477
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question