Reputation: 449
I have 2 versions of python installed on my server.
Python 2.6 in /usr/bin/python
Python 2.7.8 in /usr/src
How do I make python scripts use 2.7.8? instead of 2.6? how do I set up an alias?
Thanks
Upvotes: 0
Views: 717
Reputation: 710
There are multiple ways of doing this. First, I would suggest you check your $PATH
environment variable to see if it holds the path to both of your python versions. If it doesn't, you can either add the path or simply make a symlink to it from /usr/bin/
and call it python2.7
, for example.
Then you can use @Pavel's suggestion of specifying the path to the interpreter in the shebang
of the file.
If you followed my previous instructions, your shebang
should look something similar to the following.
#!/usr/bin/env python2.7
You could also use the second way @Pavel showed you, by simply calling the interpreter first in the terminal and pointing it to the script.
/usr/bin/python2.7 my_script.py
The best option you have, which I recommend, is using virtualenv
as suggested before, but only if you want it for specific scripts. If you want it globally, I would suggest you read further.
Finally, if you want all your scripts to run under python 2.7
then I suggest you remove python 2.6
and install the 2.7
version from the package manager, the right way, and save yourself a lot of hassle.
Upvotes: 0
Reputation: 1008
Write:
#!<path to your python interpreter>
as the first line of the script your run. Then just execute it.
Other option:
<path to your python interpreter> your_script.py
Upvotes: 1