Solved

python 2.7 full path

Posted on 2014-03-19
7
527 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
7 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 125 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 16

Assisted Solution

by:gelonida
gelonida earned 125 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 125 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 16

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 16

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 28

Assisted Solution

by:pepr
pepr earned 125 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now