English 中文(简体)
• 如何利用不同的安装方案
原标题:How to make python program use different installation
>> 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)?

我希望能够与违约相比,使用不同的平安装置,但问题是指在沙捞越类似系统的任何方案。

EDIT: To clarify, I want to run an installed program which someone else wrote and is usually run like so:

scrapy crawl blaha

NOT类似:

python scrapy crawl blaha
最佳回答

通常,根据“团结”制度,你有多种可起诉的物品,例如我的系统:

which python
/usr/bin/python
which python2
/usr/bin/python2

起诉人的姓名提供了申请文本。 http://www.python.org/dev/peps/pep-0394/“rel=“nofollow noreferer” c) 根据PEP 394 的定义,适用于不同版本的甲型六氯环己烷的标准。 如果打字本应该使用,那么通常要做的事情就是 has。 例如,在我的制度下,3. 谷歌是沙捞越的,因此,如果我写了2.x字,我补充说:

#!/usr/bin/env python2

Then, when my script is run (./some_script.py) it will use Python 2.7.3.

您应避免仅使用<条码>#!/usr/bin/env python,因为它将在不同的系统中做不同的事。 如符合规格,<代码>#!/usr/bin/env python2。 页: 1 应指出3.x——在档案中,这项工作是正确的(仅限python,指3.x(通常情况下)。

Update for your edit:

如果你想这样做,最易行的路线是使你在简单管理指挥的系统道路上受到迫害:python some_script.

This is done regularly, for example, eclipse on my system actually runs /usr/bin/eclipse - a bash script that contains:

#!/bin/bash
export ECLIPSE_HOME=/usr/share/eclipse
export GDK_NATIVE_WINDOWS=true
${ECLIPSE_HOME}/eclipse "$@"

因此,就你的问题而言,在你的道路上只作一段文字(请打<条码>/usr/bin/scrapy)。 其中:

#!/bin/bash
python2 scrapy "$@"

我要指出,今后,你应尽量提供关于你问题的信息,以便解决问题,而不是在得到答复后加以改变。

问题回答

您可查询VirtualEnv,目的是让你在安装时使用不同的录音带。

如果您希望使用已经安装的 p版,则仅使用python2.6而不是python。 如果你想要使用Python2.6。

你们如何管理你们的方案? 是否设有执行范围,并且有第一行:

#!/usr/bin/python

接着,情况良好:

#!/usr/bin/python26

或者,你可以这样做:

>> python26 your-awesome-python-script.py

关于你的话题: 既然你可以不希望改变第三方方案(治疗),你需要:

  • relink /usr/bin/python (do an ls -l on it. You will see that it points to the python24 executable, do an ln -s /usr/bin/python /usr/bin/pythonXY or similar to relink this)
  • create an alias for scrapy in your .profile
  • create your own scrapy shell script that does the proper incantations (e.g. running the script with your preferred interpreter)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...