1

Is it possible to "compile" a Python script with py2exe (or similar) and then allow the user access to modify the top-level Python scripts? Or possibly import the compiled modules into their normal Python scripts? I'm looking for the ability to distribute an easy installer for some customers, but allow other customers to build upon that installed version by creating their own scripts that work with the installed framework modules, like an API.

I have tried to use py2exe to import files that I have placed in the "dist" directory, but it complains that they aren't frozen. Why can't it use a mix of frozen binary modules and interpreted modules?

The reason that I am using py2exe is because I have some troublesome libraries (paramiko/pycrypto, plus some internally developed ones) that I don't want to require my customers to trudge through those installations. I also don't want them to have open access to my framework files. I know that they can reverse-compile the py2exe objects, but they will have to work to modify the framework, which is good enough protection.

4

2 に答える 2

1

私はそれを機能させる方法を考え出しました。「ヘッド」フレームワーク ファイルを setup.py ファイルの「includes」リストに配置しました。次に、imp モジュールを使用して通常の Python スクリプトを動的にロードするコンパイル済みのランナーがあり、それらのスクリプトはその head フレームワーク ファイルを呼び出します。これはまさに、私が探していた隠れたフレームワークでありながら到達可能な API です。

たとえば、すべての API 呼び出しを含むマスター ファイル「foo」を含む「framework」というディレクトリがあるとします。py2exe setup.py ファイルの行は次のようになります。

includes = ['framework.foo', 'some_other_module', 'etc']

次に、このランナー スクリプトのターゲットを作成します。

FrameworkTarget = Target(
    # what to build
    script = "run_framework.py",
    dest_base = "run_framework"   
    )

次に、とりわけ setup.py スクリプトの setup() コマンドにターゲットを追加します。

console = [FrameworkTarget],

コンパイルされたランナー スクリプトには、コマンド ラインから「テスト スイート」スクリプトの名前が渡されます。

test_suite_name = sys.argv[1]
file_name = test_suite_name + ".py"
path_name = os.path.join(os.getcwd(), file_name)
print "Loading source %s at %s"%(file_name, path_name)
module = imp.load_source(file_name, path_name )

次に、imp.load_source() コマンドによって呼び出されるファイルに、次のように記述します。

import framework.foo

インクルードに「framework.foo」がない場合、framework.foo のコンパイル済みバージョンが見つかりませんでした。多分誰かが将来これが役に立つと思うでしょう。Stackoverflow なしで何か役に立つことができるかどうかわかりません!

于 2013-04-29T06:37:05.763 に答える