Ich habe ein Programm, das funktioniert gut, aber wenn ich es in eine ausführbare Datei über PyInstaller
mache, habe ich Probleme. Ich führte das auf ein seltsames Verhalten zurück, das das Problem veranschaulicht. In main()
stelle ich folgende Erklärung ab:Konvertieren einer Python-Zeichenfolge in Float schlägt nur mit PyInstaller
print float('1e-07')
Wenn ich meinen normalen Python-Skript ausführen, es '1e-07'
druckt wie erwartet.
Wenn ich mein PyInstaller
.exe
Programm starte, druckt es 'ERR'
.
Weiß jemand, warum das passiert?
HINWEIS: Dies ist nicht ein esoterisches Problem, das ich erstellt habe. Ich habe eine ziemlich große Anwendung, die Strings häufig in Floats konvertiert. Ich fand, dass das Lesen in zuvor erstellten Projekten nicht mehr funktioniert und ich habe es geschafft, dies auf diesen einen Effekt zu debuggen. Ich sollte beachten, dass es manchmal die Zahlen richtig (in meinem Programm) konvertiert und manchmal nicht. Alles andere läuft gut in der Anwendung - es ist nur dieses Problem der Nummernkonvertierung. Die Leute haben mit verschiedenen Möglichkeiten geantwortet, Zahlen zu konvertieren, die nicht besser funktionieren. Jede Antwort sollte sich darauf konzentrieren, warum etwas so einfaches in Python nicht funktioniert, wenn die Anwendung mit pyinstaller erstellt wird. Derzeit kann ich keine Version dieser Software erstellen, bis ich dieses Problem beheben kann!
UPDATE: Jetzt habe ich ein Programm erstellt nur aus einer Zeile besteht, die diesen Wert druckt und druckt es als 'ERR'
im Pyinstaller
generierten Code - muss ein PyInstaller
Problem oder ein Fehler von mir sein, eine Bibliothek oder etwas schließen . Jede Hilfe wäre willkommen.
Die Datei sieht wie folgt aus:
def main():
print float('1e-07')
if __name__ == '__main__':
main()
Update erneut:
Basierend auf Empfehlungen in den Kommentaren, jetzt ist mein Code wie folgt aussieht:
import traceback
import sys
print "test"
try:
print float("1e-07")
except:
traceback.print_exc(file=sys.stdout)
keine Ausnahme ausgelöst wird und der Code druckt nur 'ERR' - wohlgemerkt nur in der PyInstaller generierten .exe-Datei - wenn er von PyScripter ausgeführt wird, wird er ordnungsgemäß ausgeführt.
Ausgabe von PyScripter:
Test
1e-07
Ausgabe von PyInstaller .exe generiert:
Test
ERR
Command Line Plus-Ausgang:
pyinstaller test.py
156 INFO: PyInstaller: 3.2
156 INFO: Python: 2.7.3
156 INFO: Platform: Windows-7-6.1.7601-SP1
156 INFO: wrote C:\work\PySI\PySIApp\test.spec
156 INFO: UPX is not available.
156 INFO: Extending PYTHONPATH with paths
['C:\\work\\PySI\\PySIApp', 'C:\\work\\PySI\\PySIApp']
156 INFO: checking Analysis
156 INFO: Building Analysis because out00-Analysis.toc is non existent
156 INFO: Initializing module dependency graph...
156 INFO: Initializing module graph hooks...
218 INFO: running Analysis out00-Analysis.toc
218 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
required by c:\python27\python.exe
328 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.2
1022.8_none_60a5df56e60dc5df.manifest
328 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.1_none_8550c6b5d18a9128.manifest
328 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.4148_none_f47e1bd6f6571810.manifest
328 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.4940_none_f47ed0f6f6564d90.manifest
328 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.6161_none_f480bfaef65491a5.manifest
437 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_none ...
437 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.307
29.6161_none_50934f2ebcb7eb57.manifest
437 INFO: Searching for file msvcr90.dll
437 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_5
0934f2ebcb7eb57\msvcr90.dll
437 INFO: Searching for file msvcp90.dll
437 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_5
0934f2ebcb7eb57\msvcp90.dll
437 INFO: Searching for file msvcm90.dll
437 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_5
0934f2ebcb7eb57\msvcm90.dll
546 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.2
1022.8_none_60a5df56e60dc5df.manifest
546 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.1_none_8550c6b5d18a9128.manifest
546 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.4148_none_f47e1bd6f6571810.manifest
546 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.4940_none_f47ed0f6f6564d90.manifest
546 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.3
0729.6161_none_f480bfaef65491a5.manifest
546 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 6161)
5677 INFO: Caching module hooks...
5677 INFO: Analyzing C:\work\PySI\PySIApp\test.py
8065 INFO: Loading module hooks...
8065 INFO: Loading module hook "hook-httplib.py"...
8081 INFO: Loading module hook "hook-encodings.py"...
8532 INFO: Looking for ctypes DLLs
8549 INFO: Analyzing run-time hooks ...
8564 INFO: Looking for dynamic libraries
17331 INFO: Looking for eggs
17331 INFO: Using Python library c:\python27\python27.dll
17331 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'x86', oldVersion=(9, 0, 21022, 8)
, newVersion=(9, 0, 30729, 6161), publicKeyToken=u'1fc8b3b9a1e18e3b')]
17331 INFO: Warnings written to C:\work\PySI\PySIApp\build\test\warntest.txt
17393 INFO: checking PYZ
17393 INFO: Building PYZ because out00-PYZ.toc is non existent
17393 INFO: Building PYZ (ZlibArchive) C:\work\PySI\PySIApp\build\test\out00-PYZ.pyz
17846 INFO: checking PKG
17846 INFO: Building PKG because out00-PKG.toc is non existent
17846 INFO: Building PKG (CArchive) out00-PKG.pkg
18017 INFO: Bootloader c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
18017 INFO: checking EXE
18017 INFO: Building EXE because out00-EXE.toc is non existent
18017 INFO: Building EXE from out00-EXE.toc
18017 INFO: Appending archive to EXE C:\work\PySI\PySIApp\build\test\test.exe
18032 INFO: checking COLLECT
18032 INFO: Building COLLECT because out00-COLLECT.toc is non existent
18032 INFO: Building COLLECT out00-COLLECT.toc
18032 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 6161)
Hier Was ist in warntest.txt:
Können Sie Ihren Code, insbesondere die Funktion 'main()', posten? – linusg
und Sie können "Test" ''? – Moberg
ja - es druckt "test" gut –