使用 easy_install 在 Cocoa 应用程序中捆绑 python 工具
我的 Cocoa 应用程序需要使用 easy_install 在用户系统上安装 Python 命令行工具。理想情况下,我希望将一个 bash 文件与我的应用程序捆绑在一起,然后我可以运行它。但据我所知这是不可能的,因为包安装在Python的“site-packages”目录中。
有没有办法创建这些文件的“包”? 如果没有,我应该如何运行 easy_install 安装?我想将 .pkg 文件与我的应用程序捆绑在一起,然后在必要时可以打开该文件,但我无法让此安装包仅运行脚本。
如果您有解决此问题的想法,我会很高兴。
亲切的问候, 法比安
My Cocoa app requires a Python command line tool to be installed on the user's system using easy_install. Ideally, I'd want to bundle one bash file with my app which I can then run. But as far as I know this is not possible, because packages are installed in the "site-packages" directory of Python.
Is there a way to create a "package" of those files?
If not, how should I run the easy_install installation? I wanted to bundle a .pkg file with my app which I can then open if necessary, but I wasn't able to let this installation package run a script only.
If you have ideas on how to fix this, I'd be glad.
Kind regards,
Fabian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以将命令行工具与您的应用程序一起提供,并且只有您的应用程序将使用它(而不是用户直接使用该工具),则您可以直接在您的应用程序中包含并使用命令行工具,如下所示:
设置相对于 Python 程序的 Python 模块搜索路径可以使用
相对路径可以使用
..
父目录约定编写:这适用于 Unix(包括Mac OS X)和 Windows。PS:如果很多程序需要访问命令行工具模块,您可以:
要么将上述代码放在每个程序中,
或者,如果您想要更容易维护的东西,您可以创建自己的模块
my_runner
并将其用作代理:您的模块my_runner
将导入所有原始的runner
功能如下所以:<块引用>
然后,您可以通过代理在所有程序中使用原始的运行程序模块,只需“正常”导入您自己的
my_runner
模块即可:<块引用>
PPS:如果您想要一个更健壮的路径,即使工作目录稍后发生更改也能正常工作,可以使用以下命令将潜在的本地路径转换为绝对路径:
path.join(path.绝对路径(路径.dirname(__file__)),...
。If you can ship the command line tool with your application, and if only your application will be using it (instead of the tool being used directly by the user), you can directly include and use the command line tool with your application like so:
Setting the Python module search path relative to a Python program can be done with
The relative path can be written with the
..
parent directory convention: this works both on Unix (including Mac OS X) and Windows.PS: If many programs need to access the command line tool module, you can:
Either put the above code in each of your programs,
or, if you want something easier to maintain, you can create your own module
my_runner
and use it as a proxy: your modulemy_runner
would import all the originalrunner
functions like so:You can then use the original runner module in all your programs through your proxy, by simply doing "normal" imports of your own
my_runner
module:PPS: If you want a more robust path that works even if the working directory later changes, it is possible to convert a potentially local path to an absolute path with:
path.join(path.abspath(path.dirname(__file__)),…
.感谢 EOL,我现在可以使用它了。该解决方案涉及下面列出的几个步骤。
通过打包
.egg
文件并像这样引用它们来删除依赖项:从现在独立的 python 构建单个
.egg
文件使用setup.py
的模块使用
1.
.egg
文件和命令行工具,我希望这对某人有用。
Thanks to EOL I got it working now. The solution involved several steps listed below.
Remove dependencies by packaging the
.egg
files and referencing them like this:Build a single
.egg
file from the now independent python module usingsetup.py
.egg
file in the command line tool like in1.
.egg
file and the command line tool in the Cocoa appI hope this will be useful to someone.