使用另一個 Python 文件的主 Python 文件(我想轉換為 .exe) (Main Python File Using Another Python File (I Want To Convert To .exe))


問題描述

使用另一個 Python 文件的主 Python 文件(我想轉換為 .exe) (Main Python File Using Another Python File (I Want To Convert To .exe))

我創建了一個包含 2 個 .py 文件的程序。我想讓程序成為一個 .exe 文件,我使用 cx_Freeze 來實現。我的問題是我將 main.py 轉換為 .exe 但第二個 Python 文件仍然是 .py 文件。我不希望它是 .py 因為如果它是用戶可以看到代碼。如果我還轉換了第二個 Python 文件,則程序無法運行,因為我在主文件中 import 了 Python 文件。有什麼建議麼?(我不想將第二個 Python 文件複製到主 Python 文件)


參考解法

方法 1:

You are chasing the wrong rabbit here. The various tools that generate executable files from Python code are not compilers. They are just tools that embed a Python interpretor with py (or pyc) files to allow users to use the program without a prior Python installation.

Said differently you should not use them to hide your code (except from people not knowing a lot of Python): a pyc does not contain text code but according to the answers to Is it possible to decompile a compiled .pyc file into a .py file? , tools exists that convert back a pyc file into a py file (of course except the comments).

IMHO, you should better google for python obfuscate to find tools dedicated to obfuscation, what neither cx‑freeze nor pyinstaller are.

BTW while there are appropriate use cases for obfuscation you should be aware that a determinate attacker can always circumvent it. The reason why the real protection for intellectual property is law and not technics...

方法 2:

I'm not sure how two or more .py files can be converted to .exe.

But in python the easiest way to convert to .exe is a module named pyinstaller .

You can install it using command pip install pyinstaller can get it . After just go to the directory where your project files are and open command prompt in that directory and execute pyinstaller file_name

(by user14674970Serge BallestaSaffron‑codes)

參考文件

  1. Main Python File Using Another Python File (I Want To Convert To .exe) (CC BY‑SA 2.5/3.0/4.0)

#exe #Python #cx-freeze






相關問題

lauch4j 你好世界程序 (lauch4j hello world program)

在具有提升權限的自己的目錄中啟動 .exe (Launching .exe in its own directory with elevation priviledges)

Я запампаваў файл .exe, але ён хутка зачыняецца пры адкрыцці (I've downloaded an .exe file but it closes quickly as it opens)

Ці добрая ідэя абараніць exe-файл з дапамогай os.path.exists? (Is it a good idea to protect a exe file using os.path.exists?)

如何將我的 Java 程序轉換為 .exe 文件? (How can I convert my Java program to an .exe file?)

有沒有辦法從 firefox 和 chrome 啟動 exe 應用程序 (Is there a way to launch exe application from firefox and chrome)

打開 .jar 文件時發生 java 異常 (a java exception has occured while opening .jar file)

錯誤,不運行程序(Windows) (error, not run program (windows))

如何從LabVIEW上編寫的應用程序(Exe)將數據返回到命令行界面? (How to return data to Command line Interface from Application (Exe) written on LabVIEW?)

pyinstaller --onefile 不會復制必要的文件 (pyinstaller --onefile doesn't copy necessary file)

系統找不到指定的路徑 - 批處理到exe (The system cannot find the path specified - batch to exe)

使用另一個 Python 文件的主 Python 文件(我想轉換為 .exe) (Main Python File Using Another Python File (I Want To Convert To .exe))







留言討論