安装python应用程序的简单方法,无需在sitepackag中使用python path或muli symlink

2024-10-02 02:43:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我不想使用easy install、站点包中的符号链接或PYTHONPATH来安装python模块。
所以,我正在尝试一些我想要的系统范围的东西,然后任何应用程序的安装都是在本地完成的。注意,这里只需要根密码一次。在

首先创建…/pythonX.Y/site-packages/mymodules->;/home/me/lib/python\u related的符号闪烁

所以,我创建了一个名为

/home/me/lib/python_related/

在那里:

^{pr2}$

现在,内容如下:

/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即可。在

现在有个问题。这是个好办法吗?在


Tags: installandthetoincmdyou应用程序

热门问题