>> which python
/usr/bin/python
>> python --version
Python 2.4.x
My problem is very simple, how do I run a python program on a different installation of python (e.g. /usr/bin/python26)?
I want to be able to run Scrapy with a different python installation than the default, but the question is meant for any program written in Python running on a Unix-like system.
EDIT: To clarify, I want to run an installed program which someone else wrote and is usually run like so:
scrapy crawl blaha
NOT like so:
python scrapy crawl blaha
Normally, under Unix systems, you have multiple Python executables, for example, on my system:
The name of the executable gives the version of the application. This is the standard for different versions of Python, as defined in PEP 394. To hint at which version your script should use, the normal thing to do is provide a hashbang. For example, on my system, Python 3.x is the default Python, so if I write a 2.x script, I add:
Then, when my script is run (
./some_script.py) it will use Python 2.7.3.You should avoid using just
#!/usr/bin/env pythonas it will do different things on different systems. If they are following the specifications,#!/usr/bin/env python2should point to 2.x and#!/usr/bin/env python3should point to 3.x – under Arch this works correctly (with justpythonpointing to 3.x (unusually) as well).Update for your edit:
If you want to do that, the easiest route is to make an executable in your system path that simply runs the command
python some_script ....This is done regularly, for example,
eclipseon my system actually runs/usr/bin/eclipse– a bash script that contains:So for your problem, just make a script somewhere in your path (let’s say
/usr/bin/scrapy) which contains:I would note that in future, you should try to give as much information about your problem as possible up front, not changing it after getting answers.