?
Solved

python 2.7 full path

Posted on 2014-03-19
7
Medium Priority
?
551 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 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

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. …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

839 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