7

New to Python and programming in general. I want to "install" a module from the command line for v 2.6, but it looks like my default Python is 2.5. (python --version returns 2.5.4)

How can I run my python setup.py build/install on 2.6 instead?

Many thanks in advance,

Brock

asked Jul 6, 2010 at 18:42
1

5 Answers 5

8

You can use explicit paths:

c:\python26\python setup.py install
c:\python25\python setup.py install

Recent versions of Python install PyLauncher. It is installed in the path so no need to add an explicit Python to the path, and it allows easy switching between multiple Python versions.

Examples:

py -3 setup.py # run latest Python 3
py -2 setup.py # run latest Python 2
py -3.3
py -2.7-32 # use 32-bit version
py # run default version

The default version can be specified in the environment variable PY_PYTHON, e.g. PY_PYTHON=3 (latest Python 3).

answered Jul 6, 2010 at 20:06
Sign up to request clarification or add additional context in comments.

Comments

4

It depends on your operating system. If you have python 2.6 installed, you need to change your environment path to point to the 2.6 executable rather than the 2.5 executable. Do a Google search for changing your PATH variable on your operating system.

answered Jul 6, 2010 at 18:46

1 Comment

Just for reference: this was a great help people.cis.ksu.edu/~schmidt/301f09/setpath.html
4

If you're on Windows and you just need to run a different version of Python temporarily or, as was the case for me, a third party program needs to run a different version of Python, then modify your path at the command prompt:

> python --version
> set PATH=<path-to-desired-python-version>;%PATH%
> python --version

For me it was:

> python --version
Python 3.4.2
> set PATH=C:\tools\python2\;%PATH%
> python --version
Python 2.7.9
> npm install...
(success)

This allowed the third party program to install successfully. The PATH modification only affects programs running in the same command prompt session and only lasts as long as the command prompt session..

answered Jan 6, 2015 at 14:38

Comments

1

They are a couple of ways you can do this 1) python virtual environment 2) pylauncher 3) Changing your windows path variable, tedious to say the least

All three outlined in this video https://www.youtube.com/watch?v=ynDlb0n27cw

answered May 21, 2017 at 16:53

Comments

0

It sounds like you are on windows. If so, run this with the python you want, to set that python as the windows one. (not my code)

import sys
from _winreg import *
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
 installpath, installpath, installpath
)
def RegisterPy():
 try:
 reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
 except EnvironmentError:
 try:
 reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
 except Exception, e:
 print "*** Unable to register: %s" % e
 return
 SetValue(reg, installkey, REG_SZ, installpath)
 SetValue(reg, pythonkey, REG_SZ, pythonpath)
 CloseKey(reg)
 print "--- Python %s at %s is now registered!" % (version, installpath)
if __name__ == "__main__":
 RegisterPy()
answered Apr 9, 2012 at 2:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.