How to use Pyinstaller in Python 3?

Asked

Viewed 1,879 times

1

I’m developing a system with the image structure below:

inserir a descrição da imagem aqui

How do I create an executable for "Transmorphus.py"?

I have tried using Pyinstaller and never opens the system.

I’ve searched several sites but all I’ve seen only tells how to use Pyinstaller with a script now with structure, where there is also the visual part with Pyqt5 no.

Someone can help me on this journey?

I tried using the command based on the tips of our colleague @Jeanextreme002 with the command below, but generates the image error then.

pyinstaller --onefile --windowed --path=config --path=lib --path=public --path=scd --path=systems --path=ui --path=views Transmorphus.py

inserir a descrição da imagem aqui

The file . SPEC is as follows::

# -*- mode: python -*-

block_cipher = None


a = Analysis(['Transmorphus.py'],
             pathex=['config', 'lib', 'public', 'scd', 'systems', 'ui', 'views', 'D:\\Estudos_Oficial\\Python\\Transmorphus'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='Transmorphus',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=False )

What could be wrong?

  • I found out what was happening of the error and why not be opening the system. When I create the executable, I pass the entire folder structure and put it inside the folder "dist" or better yet, I take the executable that is inside the folder "dist" and put it in the root folder of my system along with all other folders. Thank you all.

1 answer

0

If what you want is to generate one .exe packaging these directories into the program, you can use the command --paths=<diretório>. What this command will do is simply "add" the directory inside the executable.

Now, if your problem is related to an import failure while running the .exe, you can use the command --hidden-import=<módulo_ou_pacote>.

Example: pyinstaller -F --paths=src --hidden-import=tkinter app.py

  • A doubt. In case I would put all directories with comma separating type like this: -paths=config, lib, public, systems, ui, views ?

  • I honestly don’t know, but I usually put the "-paths=" command for each directory.

  • I tried comma to separate the directories and it didn’t work. It simply merges the names if you try (example: "subpath/config,lib,public"). You’ll have to actually put one command at a time.

  • I edited my question based on your tips and ran some tests and it didn’t work. afff. I wonder what might be going on?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.