Muitas vezes nossos códigos puxam informações de outros arquivos ou, no caso de webscraping, usam outros arquivos como o chromedriver.exe para funcionar.
Nesses casos, precisamos não só tomar alguns cuidados, mas também adaptar o nosso código para funcionar.
-
auto-py-to-exe para transformar o arquivo python em executável
-
pathlib ou os para adaptar todos os "caminhos dos arquivos"
-
Alternativamente, podemos usar o tkinter que nos permiti escolher manualmente o arquivo, independente do computador que vamos rodar o programa
-
Referências Úteis:
A .py to .exe converter using a simple graphical interface and PyInstaller in Python.
阅读中文版的README ,点击 这里
- Python : 3.6-3.11
To have the interface displayed in the images, you will need chrome. If chrome is not installed or --no-chrome is supplied, the default browser will be used.
As of PyInstaller 4.0, Python 2.7 is no longer supported. Read "Python 2.7 Support" below for steps on how to use this tool with Python 2.7.
Installing Via PyPI
You can install this project using PyPI:
$ pip install auto-py-to-exe
Then to run it, execute the following in the terminal:
$ auto-py-to-exe
Installing Via GitHub
$ git clone https://github.com/brentvollebregt/auto-py-to-exe.git
$ cd auto-py-to-exe
$ python setup.py install
Then to run it, execute the following in the terminal:
$ auto-py-to-exe
Running Locally Via Github (no install)
You can run this project locally by following these steps:
- Clone/download the repo
- Open cmd/terminal and cd into the project
- Execute
python -m pip install -r requirements.txt
Now to run the application, execute python -m auto_py_to_exe
. A Chrome window in app mode will open with the project running inside.
Make sure you are in the directory below auto_py_to_exe (you will be after step 3) when calling
python -m auto_py_to_exe
or you will need to reference the folder auto_py_to_exe absolutely/relatively to where you currently are.
- Select your script location (paste in or use a file explorer)
- Outline will become blue when file exists
- Select other options and add things like an icon or other files
- Click the big blue button at the bottom to convert
- Find your converted files in /output when completed
Easy.
Usage: auto-py-to-exe [-nc] [-c [CONFIG]] [-o [PATH]] [filename]
Argument | Type | Description |
---|---|---|
filename | positional/optional | Pre-fill the "Script Location" field in the UI. |
-nc, --no-chrome | optional | Open the UI using the default browser (which may be Chrome). Will not try to find Chrome. |
-nu, --no-ui | optional | Don't try to open the UI in a browser and simply print out the address that the application can be accessed at. |
-c [CONFIG], --config [CONFIG] | optional | Provide a configuration file (json) to pre-fill the UI. These can be generated in the settings tab. |
-o [PATH], --output-dir [PATH] | optional | Set the default output directory. This can still be changed in the ui. |
-bdo [FOLDER_PATH], --build-directory-override [FOLDER_PATH] | optional | Override the default build directory. Useful if you need to whitelist a folder to stop your antivirus from removing files. |
-lang [LANGUAGE_CODE], --language [LANGUAGE_CODE] | optional | Hint the UI what language it should default to when opening. Language codes can be found in the table under "Translations" below. |
If you are running this package locally, you will need to call
python -m auto_py_to_exe
instead ofauto-py-to-exe
Instead of inserting the same data into the UI over and over again, you can export the current state by going to the "Configuration" section within the settings tab and exporting the config to a JSON file. This can then be imported into the UI again to re-populate all fields.
This JSON config export action does not save the output directory automatically as moving hosts could mean different directory structures. If you want to have the output directory in the JSON config, add the directory under nonPyinstallerOptions.outputDirectory
in the JSON file (will need to create a new key).
If you need something visual to help you get started, I made a video for the original release of this project; some things may be different but the same concepts still apply.
If you're having issues with the packaged executable or using this tool in general, I recommend you read my blog post on common issues when using auto-py-to-exe. This post covers things you should know about packaging Python scripts and fixes for things that commonly go wrong.
Language | Code | Translator | Translated |
---|---|---|---|
Arabic (العربية) | ar | Tayeb-Ali | UI |
Brazilian Portuguese (Português Brasileiro) | pt_br | marleyas | UI (partial) |
Chinese Simplified (简体中文) | zh | jiangzhe11 | UI and README |
Chinese Traditional (繁體中文) | zh_tw | startgo | UI |
Czech | cz | Matto58 | UI |
English | en | - | UI and README |
French (Français) | fr | flaviedesp | UI |
German (Deutsch) | de | hebens | UI (partial) |
Greek (Ελληνικά) | gr | sofronas | UI |
Indonesian (Bahasa Indonesia) | id | MarvinZhong | UI |
Italian (Italiano) | it | itsEmax64 | UI |
Russian (Русский) | ru | Oleg | UI |
Spanish (Español) | sp | enriiquee | UI |
Thai (ภาษาไทย) | th | teerut26 | UI (partial) |
Turkish (Türkçe) | tr | mcagriaksoy | UI |
Want to add a translation for another language? Update i18n.js and submit a PR or attach it in an issue.
As of PyInstaller v4.0 released on Aug 9 2020, Python 2.7 is no longer supported; although you can still use this tool with Python 2.7 by installing an older version of PyInstaller. PyInstaller v3.6 was the last version that supported Python 2.7; to install this, first uninstall any existing versions of PyInstaller and then execute python -m pip install pyinstaller==3.6
.
Tests are located in tests/
and are run using pytest:
$ pip install pytest
$ pip install -e .
$ pytest