Reputation: 1
When i perform the command bellow, i get this error:
pyinstaller --onefile --windowed app.pyw
Traceback (most recent call last):
File "app.pyw", line 1, in <module>
import eel
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
File "eel\__init__.py", line 15, in <module>
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
File "bottle.py", line 73, in <module>
AttributeError: 'NoneType' object has no attribute 'write'
My python script:
import eel
import pyperclip
eel.init('app/www')
total_seconds = 0
@eel.expose
def converter_tempo(minutes, seconds):
total_seconds = (minutes * 60) + seconds
pyperclip.copy(total_seconds)
return total_seconds
eel.start('index.html', size=(480, 730))
My HTML/JS script:
<template>
<div class="page" data-name="home">
<!-- Top Navbar -->
<div class="navbar navbar-large">
<div class="navbar-bg"></div>
<div class="navbar-inner sliding">
<div class="title">Conversor Minutos/Segundos</div>
<div class="title-large">
<div class="title-large-text">Conversor Minutos/Segundos</div>
</div>
</div>
</div>
<!-- Toolbar-->
<div class="toolbar toolbar-bottom">
<div class="toolbar-inner">
<a href="#" class="link" @click="${fecharApp}">Fechar</a>
<a href="#" class="link convert-form-to-data">Converter</a>
</div>
</div>
<!-- Scrollable page content-->
<div class="page-content">
<form class="list list-strong-ios list-dividers-ios list-outline-ios" id="formDados">
<ul>
<li class="item-content item-input item-input-outline">
<div class="item-content item-input width-100">
<div class="item-inner">
<div class="item-title item-label">Minutos</div>
<div class="item-input-wrap">
<input type="number" name="minutes" placeholder="Informe os minutos" />
</div>
</div>
</div>
</li>
<li class="item-content item-input item-input-outline">
<div class="item-content item-input width-100">
<div class="item-inner">
<div class="item-title item-label">Segundos</div>
<div class="item-input-wrap">
<input type="number" name="seconds" placeholder="Informe os segundos" />
</div>
</div>
</div>
</li>
</ul>
</form>
<div id="resultado" class="block border-color-primary"></div>
</div>
</div>
</template>
<script>
export default (props, { $, $on, $f7 }) => {
$on('pageInit', () => {
$('.convert-form-to-data').on('click', function () {
let formData = $f7.form.convertToData('#formDados');
chamarConverterTempo(formData);
});
});
const fecharApp = () => {
window.close();
}
const chamarConverterTempo = async ({minutes, seconds}) => {
// Chamar a função converter_tempo do Python e esperar pelo resultado
let total_seconds = await eel.converter_tempo(parseInt(minutes), parseInt(seconds))();
console.log(total_seconds);
// Exibir o resultado na página
document.getElementById('resultado').innerText = 'Total em segundos: ' + total_seconds;
}
return $render;
}
</script>
The all log i get in the terminal:
389 INFO: PyInstaller: 6.5.0, contrib hooks: 2024.3
389 INFO: Python: 3.12.2
422 INFO: Platform: Windows-11-10.0.22631-SP0
425 INFO: wrote C:\workspace\ConvMinSeg\app.spec
436 INFO: Extending PYTHONPATH with paths
['C:\\workspace\\ConvMinSeg']
806 INFO: checking Analysis
831 INFO: Building because C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_inspect.py changed
831 INFO: Initializing module dependency graph...
832 INFO: Caching module graph hooks...
884 INFO: Analyzing base_library.zip ...
2624 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
2745 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
4925 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
7666 INFO: Caching module dependency graph...
7756 INFO: Running Analysis Analysis-00.toc
7756 INFO: Looking for Python shared library...
7764 INFO: Using Python shared library: C:\Users\bruno\AppData\Local\Programs\Python\Python312\python312.dll
7764 INFO: Analyzing C:\workspace\ConvMinSeg\app.pyw
7778 INFO: Loading module hook 'hook-eel.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
7808 INFO: Loading module hook 'hook-jinja2.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
8803 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
9032 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
10029 INFO: Loading module hook 'hook-gevent.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
11960 INFO: Loading module hook 'hook-platform.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
11974 INFO: Loading module hook 'hook-zope.interface.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
12073 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
13842 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
14077 INFO: Loading module hook 'hook-pkg_resources.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
15392 INFO: Processing module hooks...
15704 INFO: Loading module hook 'hook-pycparser.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
16193 INFO: Loading module hook 'hook-setuptools.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
18310 INFO: Processing pre-safe import module hook distutils from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-distutils.py'.
19303 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
19307 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
19431 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
19779 INFO: Loading module hook 'hook-packaging.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
21703 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
25636 INFO: Loading module hook 'hook-setuptools._distutils.command.check.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
26027 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
26028 INFO: checking Tree
26139 INFO: checking Tree
26165 INFO: checking Tree
26175 INFO: Loading module hook 'hook-distutils.command.check.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
26191 INFO: Performing binary vs. data reclassification (978 entries)
31611 INFO: Looking for ctypes DLLs
31659 INFO: Analyzing run-time hooks ...
31663 INFO: Including run-time hook 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
31665 INFO: Including run-time hook 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
31668 INFO: Processing pre-find module path hook _pyi_rth_utils from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-_pyi_rth_utils.py'.
31673 INFO: Loading module hook 'hook-_pyi_rth_utils.py' from 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
31674 INFO: Including run-time hook 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
31677 INFO: Including run-time hook 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
31681 INFO: Including run-time hook 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_setuptools.py'
31682 INFO: Including run-time hook 'C:\\Users\\bruno\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
31717 INFO: Looking for dynamic libraries
32698 INFO: Extra DLL search directories (AddDllDirectory): []
32699 INFO: Extra DLL search directories (PATH): []
33164 INFO: Warnings written to C:\workspace\ConvMinSeg\build\app\warn-app.txt
33243 INFO: Graph cross-reference written to C:\workspace\ConvMinSeg\build\app\xref-app.html
33311 INFO: checking PYZ
33323 INFO: Building because C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\fake-modules\_pyi_rth_utils\__init__.py changed
33323 INFO: Building PYZ (ZlibArchive) C:\workspace\ConvMinSeg\build\app\PYZ-00.pyz
34333 INFO: Building PYZ (ZlibArchive) C:\workspace\ConvMinSeg\build\app\PYZ-00.pyz completed successfully.
34377 INFO: checking PKG
34391 INFO: Building because toc changed
34392 INFO: Building PKG (CArchive) app.pkg
37638 INFO: Building PKG (CArchive) app.pkg completed successfully.
37660 INFO: Bootloader C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\runw.exe
37661 INFO: checking EXE
37685 INFO: Building because toc changed
37685 INFO: Building EXE from EXE-00.toc
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\__main__.py", line 228, in _console_script_run
run()
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\__main__.py", line 212, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\__main__.py", line 69, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\build_main.py", line 1139, in main
build(specfile, distpath, workpath, clean_build)
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\build_main.py", line 1079, in build
exec(code, spec_namespace)
File "C:\workspace\ConvMinSeg\app.spec", line 18, in <module>
exe = EXE(
^^^^
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\api.py", line 628, in __init__
self.__postinit__()
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
self.assemble()
File "C:\Users\bruno\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\api.py", line 722, in assemble
os.remove(self.name)
Obs.: i try execute as adm and get the same error
I have trying thats tips i get from Copilot:
When using PyInstaller to create an executable from your Python script, you can include additional data files using the --add-data
option. This allows you to bundle extra files (such as configuration files, images, or other resources) with your compiled executable. Here are the steps to add data files:
Command Line Approach:
--add-data
flag followed by the path to your data file and its destination within the executable. The format is {source}{os_separator}{destination}
.os_separator
is platform-specific: ;
on Windows and :
on most Unix systems.main.kv
from the current directory:
pyinstaller -F --add-data "main.kv;." yourtarget.py
pyinstaller -F --add-data "main.kv;." --add-data "otherfile.txt;." yourtarget.py
Spec File Approach:
.spec
file by running PyInstaller once (it will create a .spec
file for your script)..spec
file directly to include your data files.datas
parameter in the .spec
file to specify the source and destination for each file.a = Analysis(
...
datas=[("main.kv", ".")],
...
)
Remember that this approach allows you to bundle additional files into your executable, making it self-contained and portable.
When using PyInstaller to bundle your Python application into an executable, you can include additional data files using the --add-data
option. This allows you to package non-binary files (such as configuration files, images, or other resources) along with your executable.
Here are two ways to achieve this:
Command Line Approach:
--add-data
parameter followed by the source and destination paths. The format is {source}{os_separator}{destination}
.os_separator
is platform-specific: ;
on Windows and :
on most Unix systems.pyinstaller -F --add-data "main.kv;." yourtarget.py
Spec File Approach:
.spec
file by running PyInstaller once (it creates the .spec
file automatically)..spec
file to include your data files.datas
parameter in the .spec
file to specify the source and destination paths.a = Analysis(
...
datas=[("main.kv", ".")],
...
)
The error you're encountering, AttributeError: 'NoneType' object has no attribute 'write'
, typically occurs when PyInstaller or another packaging tool fails to handle certain Python modules or libraries correctly⁵. This issue might be due to the specific version of PyInstaller you're using⁴.
Here are a few potential solutions:
Specify a different version of PyInstaller: You could try uninstalling the current version of PyInstaller and installing a different version. For example, you could use the command pip install pyinstaller==5.4.0
³.
Check for buffer-related operations in your code: Look for any operations related to the buffer in your code, such as sys.stdout.flush()
, and consider commenting out these lines³.
That last one solution, i dont know where i need to modify:
You can use the pyuac
module in your Python script to invoke User Access Control (UAC) in Windows. This allows a Python process to re-spawn a new process with Administrator level rights using the UAC prompt¹. Here's an example of how to use it:
from pyuac import main_requires_admin
@main_requires_admin
def main():
print("Do stuff here that requires being run as an admin.")
# The window will disappear as soon as the program exits!
input("Press enter to close the window. >")
if __name__ == "__main__":
main()
In this example, the @main_requires_admin
decorator ensures that your script's main()
function will respawn itself as Admin if necessary¹. If you want to capture the stdout and stderr of your Admin sub-process, you can use the decorator like this:
from pyuac import main_requires_admin
@main_requires_admin(return_output=True)
def main():
print("Do stuff here that requires being run as an admin.")
# The window will disappear as soon as the program exits!
input("Press enter to close the window. >")
if __name__ == "__main__":
rv = main()
if not rv:
print("I must have already been Admin!")
else:
admin_stdout_str, admin_stderr_str, *_ = rv
if "Do stuff" in admin_stdout_str:
print("It worked.")
In this case, rv
will contain the stdout and stderr of your Admin sub-process¹. You can check these for errors from the non-admin parent¹.
Upvotes: 0
Views: 127