0

簡単なインストール、サイトパッケージのシンボリックリンク、または PYTHONPATH を使用して Python モジュールをインストールしたくありませんでした。
だから、私はシステム全体で何かをしようとしています。その後、アプリケーションのインストールはローカルで行われます。root パスワードはここで 1 回だけ必要であることに注意してください。

最初に .../pythonX.Y/site-packages/mymodules -> /home/me/lib/python_related のシンボリック リンクを作成します。

だから、私はというディレクトリを作成します

/home/me/lib/python_related/

そこで:

/home/me/lib/python_related
/home/me/lib/python_related/__init__.py
/home/me/lib/python_related/django_related/
/home/me/lib/python_related/django_related/core
/home/me/lib/python_related/django_related/core/Django1.0
/home/me/lib/python_related/django_related/core/Django1.1
/home/me/lib/python_related/django_related/core/mycurrent_django -> Django1.1/django
/home/me/lib/python_related/django_related/apps
/home/me/lib/python_related/django_related/apps/tagging
/home/me/lib/python_related/django_related/apps/tagging/django-tagging-0.2
/home/me/lib/python_related/django_related/apps/tagging/django-tagging-0.3
/home/me/lib/python_related/django_related/apps/tagging/mycurrent_tagging -> django-tagging-0.3

さて、内容は以下の通りです。

/home/me/lib/python_related/__init__.py

==========================================
import sys, os

# tell us where you keep all your modules and this didn't work as it gave me
# the location of the site-packages
#PYTHON_MODULE_PATH = os.path.dirname(__file__)
PYTHON_MODULE_PATH = "/home/me/libs/python_bucket"

def run_cmd(cmd):
        """
        Given a command name, this function will run the command and returns the output
        in a list.
        """
        output = []
        phdl = os.popen(cmd)
        while 1:
                line = phdl.readline()
                if line == "":
                        break
                output.append(line.replace("\n", ""))
        return output

def install():
        """
        A cheesy way of installing and managing your python apps locally without
        a need to install them in the site-package. All you'd need is to install
        the directory containing this file in the site-package and that's it.
        Anytime you have a python package you want to install, just put it in a
        proper sub-directory and make a symlink to that directory called mycurrent_xyz
        and you are done. (e.g. mycurrent_django, mycurrent_tagging .. etc)
        """
        cmd = "find %s -name mycurrent_*" % PYTHON_MODULE_PATH
        modules_to_be_installed = run_cmd(cmd)
        sys.path += modules_to_be_installed

install()
=======================================================

これで、新しい python プロジェクトで mymodules をインポートするだけで、上記のディレクトリにあるアプリが適切なシンボリック リンクで取り込まれます。このようにして、アプリの複数のコピーを作成し、使用したいものに mycurrent_xyz を使用するだけです。

ここで質問です。これは良い方法ですか?

4

1 に答える 1

4

virtualenvを見てください。

それはあなたが求めていることをするかもしれません。

于 2009-09-08T04:19:34.847 に答える