3

我的 Cocoa 应用程序需要使用 easy_install 在用户系统上安装 Python 命令行工具。理想情况下,我想将一个 bash 文件与我的应用程序捆绑在一起,然后我可以运行它。但据我所知,这是不可能的,因为软件包安装在 Python 的“site-packages”目录中。

有没有办法创建这些文件的“包”?如果没有,我应该如何运行 easy_install 安装?我想将一个 .pkg 文件与我的应用程序捆绑在一起,然后我可以在必要时打开它,但我不能让这个安装包只运行一个脚本。

如果您对如何解决此问题有任何想法,我会很高兴。

亲切的问候,法比安

4

2 回答 2

4
于 2012-01-14T10:59:44.327 回答
2

Thanks to EOL I got it working now. The solution involved several steps listed below.

  1. Remove dependencies by packaging the .egg files and referencing them like this:

    import sys
    import os.path as path
    sys.path.append(path.join(path.dirname(__file__), '<relative path to .egg file>'))
    
    from dependency import something
    
  2. Build a single .egg file from the now independent python module using setup.py

  3. Reference the resulting .egg file in the command line tool like in 1.
  4. Bundle the single .egg file and the command line tool in the Cocoa app

I hope this will be useful to someone.

于 2012-01-14T14:21:24.447 回答