0

I have several python versions installed (and working properly on my machines). Isn't there a way to execute a specific version of python from the command line.

Say I want to use python 3.1. I am after something a SIMPLE COMMAND such as python3.1 or python31 that would be used as follows :python3.1 setup.py install, for instance.

[pip has pip3.1 to install a library with the version 3.1 of python, specifically]

2
  • 1
    On Linux, you'd normally have the executables in /usr/bin/. Usually, the name of the executables is python3.4, python2.7...etc so you should already be able to use them in the format you're asking for without any changes. Commented May 14, 2015 at 11:14
  • You can also manipulate your $PATH just prior to executing the Python code, so that the path to the particular Python version you use is at the front of $PATH. Commented May 15, 2015 at 6:38

2 Answers 2

2

Yes, this is possible, but the best approach varies depending on the OS you're using. For Windows, you want the py launcher, for which instructions are here. For Mac OS X and Linux, you could use something like pyenv. Of course, you could always build your own solution using virtualenv.

Sign up to request clarification or add additional context in comments.

Comments

0

There are multiple ways to go about this. As Sir_FZ pointed out, the executables are already named python2.7, etc, so what you want already exists. If for some really odd reason you have more than one python2.7 in your $PATH, you can explicitly call /my/other/python2.7 etc. If you're lazy, you can even create alias's alias p2=/my/other/python2.7 and then you can call p2 setup.py install

If you're going to be doing this for more than a day, I'd suggest following one of Sagar's links.

Comments

Your Answer

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.