<i id='BXwYb'><tr id='BXwYb'><dt id='BXwYb'><q id='BXwYb'><span id='BXwYb'><b id='BXwYb'><form id='BXwYb'><ins id='BXwYb'></ins><ul id='BXwYb'></ul><sub id='BXwYb'></sub></form><legend id='BXwYb'></legend><bdo id='BXwYb'><pre id='BXwYb'><center id='BXwYb'></center></pre></bdo></b><th id='BXwYb'></th></span></q></dt></tr></i><div id='BXwYb'><tfoot id='BXwYb'></tfoot><dl id='BXwYb'><fieldset id='BXwYb'></fieldset></dl></div>

      <bdo id='BXwYb'></bdo><ul id='BXwYb'></ul>

      <legend id='BXwYb'><style id='BXwYb'><dir id='BXwYb'><q id='BXwYb'></q></dir></style></legend><tfoot id='BXwYb'></tfoot>

      <small id='BXwYb'></small><noframes id='BXwYb'>

    1. 配置 Python 以使用站点包的其他位置

      时间:2023-09-14
      <tfoot id='FThuy'></tfoot>
          <tbody id='FThuy'></tbody>
          <legend id='FThuy'><style id='FThuy'><dir id='FThuy'><q id='FThuy'></q></dir></style></legend>

        1. <i id='FThuy'><tr id='FThuy'><dt id='FThuy'><q id='FThuy'><span id='FThuy'><b id='FThuy'><form id='FThuy'><ins id='FThuy'></ins><ul id='FThuy'></ul><sub id='FThuy'></sub></form><legend id='FThuy'></legend><bdo id='FThuy'><pre id='FThuy'><center id='FThuy'></center></pre></bdo></b><th id='FThuy'></th></span></q></dt></tr></i><div id='FThuy'><tfoot id='FThuy'></tfoot><dl id='FThuy'><fieldset id='FThuy'></fieldset></dl></div>

          <small id='FThuy'></small><noframes id='FThuy'>

            • <bdo id='FThuy'></bdo><ul id='FThuy'></ul>

              1. 本文介绍了配置 Python 以使用站点包的其他位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                有没有办法在不修改现有脚本的情况下告诉 Python 其他 site-packages 位置?

                在我的 CentOS 5.5 服务器上,我有一个安装在 /opt/python2.7.2 中的 Python 2.7 安装,并且 中有一个 site-packages 文件夹/opt/python2.7.2/lib/python2.7/site-packages.

                这样做的原因是我不想干扰 5.5 发行版附带的现有 Python 2.4 安装.

                然而,第三方 Python 应用程序还在 /usr/local/lib/python2.7/site-packages 添加了一个 site-packages 文件夹,并将其自身安装在那个位置.

                这部分是我的错,因为我没有在安装之前调整应用程序的 Makefile 中的 PREFIX,但是我现在无能为力.

                我知道我可以做到:

                导入系统;sys.path.insert(0, "/usr/local/lib/python2.7/site-packages")

                但是,这将涉及我跟踪每个脚本并添加上述内容,如果将来有更新,这并不理想.

                为了解决这个问题,我在 /opt/python2.7.2/lib/python2.7/site-packages 中创建了一个指向此第三方应用程序位置的符号链接:

                <上一页>ln -sf/usr/local/lib/python2.7/site-packages/theapp/opt/python2.7.2/lib/python2.7/site-packages/theapp

                这似乎工作正常,但我想知道是否有更好的方法?

                解决方案

                您可以使用 Site-具体配置钩子.

                <块引用>

                "路径配置文件是一个文件名,格式为name.pth,存在于上述四个目录之一中;其内容是要添加的附加项(每行一个)到 sys.path."

                在您的情况下,您应该能够通过简单地放入包含要包含的目录路径的 .pth 文件来实现您想要的:

                [root@home]$ echo "/usr/local/lib/python2.7/site-packages/" >/opt/python2.7.2/lib/python2.7/site-packages/usrlocal.pth

                Is there a way to tell Python about additional site-packages locations without modifying existing scripts?

                On my CentOS 5.5 server I have a Python 2.7 installation that is installed in /opt/python2.7.2 and there is a site-packages folder at /opt/python2.7.2/lib/python2.7/site-packages.

                The reason for this is that I didn't want to disturb the existing Python 2.4 install that shipped with the 5.5 distribution.

                However a third party Python application also added a site-packages folder at: /usr/local/lib/python2.7/site-packages and installed itself at that location.

                This is partly my fault because I didn't tweak the PREFIX in the application's Makefile before installing, however there's not much I can do about it now.

                I know that I can do this:

                import sys; sys.path.insert(0, "/usr/local/lib/python2.7/site-packages")
                

                However it would involve me tracking down every script and adding the above which is not ideal should there be updates in the future.

                To get around this I created a symbolic link in /opt/python2.7.2/lib/python2.7/site-packages to the location of this third party application:

                ln -sf /usr/local/lib/python2.7/site-packages/theapp /opt/python2.7.2/lib/python2.7/site-packages/theapp
                

                This appears to work fine but I'm wondering if there's a better way?

                解决方案

                You can use the Site-specific configuration hook.

                "A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path."

                In your case, you should be able to achieve what you want by simply dropping in a .pth file containing the path of the directory to include:

                [root@home]$ echo "/usr/local/lib/python2.7/site-packages/" > /opt/python2.7.2/lib/python2.7/site-packages/usrlocal.pth
                

                这篇关于配置 Python 以使用站点包的其他位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在不重复导入顶级名称的情况下构造python包 下一篇:python:不同包下同名的两个模块和类

                相关文章

                最新文章

              2. <tfoot id='4d2H4'></tfoot>
              3. <legend id='4d2H4'><style id='4d2H4'><dir id='4d2H4'><q id='4d2H4'></q></dir></style></legend>

                <small id='4d2H4'></small><noframes id='4d2H4'>

                <i id='4d2H4'><tr id='4d2H4'><dt id='4d2H4'><q id='4d2H4'><span id='4d2H4'><b id='4d2H4'><form id='4d2H4'><ins id='4d2H4'></ins><ul id='4d2H4'></ul><sub id='4d2H4'></sub></form><legend id='4d2H4'></legend><bdo id='4d2H4'><pre id='4d2H4'><center id='4d2H4'></center></pre></bdo></b><th id='4d2H4'></th></span></q></dt></tr></i><div id='4d2H4'><tfoot id='4d2H4'></tfoot><dl id='4d2H4'><fieldset id='4d2H4'></fieldset></dl></div>
                  • <bdo id='4d2H4'></bdo><ul id='4d2H4'></ul>