简体   繁体   English

在PyInstaller中构建一串Python代码?

[英]Building a string of Python Code in PyInstaller?

I understand how we can package an .exe by pointing PyInstaller to a file. 我了解如何通过将PyInstaller指向文件来打包.exe。 Such like: 如:

c:\Python25\python c:\Users\Mike\Desktop\pyinstaller-1.4\Makespec.py -F -w sampleApp.py

However is there a way to create an .exe with only a string [and not a file]? 但是,有没有一种方法可以仅使用字符串[而不使用文件]创建.exe? Such as: 如:

string="""
print "Hello world"

"""

buildApplication(string) #Function Does not exist

To the best of my knowledge, I am afraid you won't be able to work around the need to create a temporary file with any of the existing standalone executable creation tools ( py2exe , PyInstaller and cxFreeze ). 就我所知,恐怕您将无法使用任何现有的独立可执行文件创建工具( py2exePyInstallercxFreeze )创建临时文件。

What I see as the most viable solution is a bit of security through obscurity, combining the following two techniques: 我认为最可行的解决方案是通过结合以下两种技术来提高安全性:

  1. Create a byte-code compiled file ( .pyc ) directly, instead of the plaintext .py file, from the generated code string, using the __builtin__.compile function (you can find on the source code of the py_compile module how to achieve this. A byte-compiled file will be significantly less useful to prying eyes than the source file. 使用__builtin__.compile函数从生成的代码字符串中直接创建字节码编译文件( .pyc ),而不是纯文本.py文件(您可以在py_compile模块的源代码上找到如何实现此目的的方法。字节编译文件在撬动眼睛方面将远没有源文件有用。
  2. A temporary file with an obscure name and location created using the tempfile module. 使用tempfile模块创建的临时文件,其名称和位置不明确。 This file will be relatively short lived, but obviously, a sufficiently determined user will be able to find it and copy it while it existes to be consumed by the executable creation tool. 该文件的生存期相对较短,但是很显然,一个足够确定的用户将能够找到该文件并将其复制,而该文件存在时将由可执行文件创建工具使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM