Solved

python 2.7 full path

Posted on 2014-03-19
7
529 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
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 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…

803 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