Lavonen
Lavonen

Reputation: 670

(Pyinstaller) creates .py copy instead of .exe copy

I have created a simple program for Windows in Python (converted to .exe with Pyinstaller) that copy itself to a created folder in Program Files. The program works perfect except one unforeseen detail, when the file copy itself to the directory it replaces the .exe extension with .py which makes the file unfunctional. Why is this happening?

Here is a very simple example that illustrate the problem:

import os
import shutil

filePath = os.path.abspath(__file__)
folder = 'some folder in C'

shutil.copy(filePath, folder)

Convert it to .exe in Pyinstaller with the following:

Pyinstaller --onefile name-of-file.py

When you run the program it will create a .py copy...

Upvotes: 0

Views: 814

Answers (1)

Maurice Meyer
Maurice Meyer

Reputation: 18106

Python is an interpreted language. PyInstaller/Py2exe/... are zipping the all python modules and add an executable header to make the exe-file executable.

When you are running the exe, all python modules are extracted to a temp directory and executed from there.

You can use sys.executable, to get the path of the exe. More details docs here.

Upvotes: 2

Related Questions