Pet*_*e P 8 python data-conversion pyinstaller
我有一个工作正常的程序,但当我把它变成可执行文件时PyInstaller,我有问题.我将其追溯到一个表明问题的奇怪行为.在main(),我发表以下声明:
print float('1e-07')
Run Code Online (Sandbox Code Playgroud)
当我运行我的普通Python脚本时,它'1e-07'按预期打印.
当我运行我的PyInstaller .exe程序时,它会打印出来'ERR'.
有谁知道为什么会这样?
NOTE: This is not some esoteric problem I created. I have a rather large application that frequently converts strings to floats. I found that reading in previously created projects doesn't work anymore and I managed to debug this down to this one effect. I should note that sometimes it converts the numbers properly (in my program) and sometimes not. Everything else runs fine in the application - it's just this number conversion problem. People have answered with different ways of converting numbers that don't work any better. Any answer should concentrate on why something so simple in Python does not work when the application is created with pyinstaller. Currently, I cannot build a release of this software until I can fix this problem!
UPDATE: Now I have created a program consisting only of one line that prints this value and it prints as 'ERR' in the Pyinstaller generated code - must be a PyInstaller problem or a failure of mine to include a library or something. Any help would be appreciated.
The file looks like this:
def main():
print float('1e-07')
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
Update Again:
Based on recommendations in comments, my code now looks like this:
import traceback
import sys
print "test"
try:
print float("1e-07")
except:
traceback.print_exc(file=sys.stdout)
Run Code Online (Sandbox Code Playgroud)
No exception is thrown and the code just prints 'ERR' - mind you this is only in the PyInstaller generated .exe file - when run from PyScripter it executes fine.
Output from PyScripter:
test
1e-07
Output from PyInstaller generated .exe:
test
ERR
Command Line plus output:
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)
Run Code Online (Sandbox Code Playgroud)
Here's what's in warntest.txt:
missing module named unicodedata.ucd_3_2_0 - imported by unicodedata, stringprep, encodings.idna
missing module named array.array - imported by array, httplib
missing module named _warnings.warn_explicit - imported by _warnings, warnings
missing module named _warnings.filters - imported by _warnings, warnings
missing module named _warnings.once_registry - imported by _warnings, warnings
missing module named _warnings.default_action - imported by _warnings, warnings
missing module named _warnings.warn - imported by _warnings, warnings
missing module named _subprocess.STD_OUTPUT_HANDLE - imported by _subprocess, subprocess
missing module named _subprocess.CREATE_NEW_PROCESS_GROUP - imported by _subprocess, subprocess
missing module named _subprocess.STD_INPUT_HANDLE - imported by _subprocess, subprocess
missing module named _subprocess.STARTF_USESHOWWINDOW - imported by _subprocess, subprocess
missing module named _subprocess.CREATE_NEW_CONSOLE - imported by _subprocess, subprocess
missing module named _subprocess.STD_ERROR_HANDLE - imported by _subprocess, subprocess
missing module named _subprocess.STARTF_USESTDHANDLES - imported by _subprocess, subprocess
missing module named _subprocess.SW_HIDE - imported by _subprocess, subprocess
missing module named cPickle.loads - imported by cPickle, collections
missing module named cPickle.dumps - imported by cPickle, collections
missing module named thread.get_ident - imported by thread, collections
missing module named thread._local - imported by thread, threading
missing module named thread.stack_size - imported by thread, threading
missing module named thread.allocate_lock - imported by thread, _strptime
missing module named itertools.chain - imported by itertools, heapq, collections
missing module named itertools.starmap - imported by itertools, collections
missing module named itertools.repeat - imported by itertools, heapq, collections
missing module named itertools.ifilterfalse - imported by itertools, sets
missing module named itertools.ifilter - imported by itertools, sets
missing module named itertools.imap - imported by itertools, heapq
missing module named itertools.tee - imported by itertools, heapq
missing module named itertools.izip - imported by itertools, heapq
missing module named itertools.count - imported by itertools, heapq
missing module named itertools.islice - imported by itertools, repr, heapq
missing module named operator.itemgetter - imported by operator, collections, heapq
missing module named operator.attrgetter - imported by operator, inspect
missing module named _collections.deque - imported by _collections, collections
missing module named _collections.defaultdict - imported by _collections, collections
missing module named _weakref.ref - imported by _weakref, _weakrefset, weakref
missing module named _weakref.ReferenceType - imported by _weakref, weakref
missing module named _weakref.proxy - imported by _weakref, weakref
missing module named _weakref.getweakrefs - imported by _weakref, weakref
missing module named _weakref.getweakrefcount - imported by _weakref, weakref
missing module named _weakref.ProxyType - imported by _weakref, weakref
missing module named _weakref.CallableProxyType - imported by _weakref, weakref
missing module named time.time - imported by time, threading
missing module named time.sleep - imported by time, threading
missing module named datetime.date - imported by datetime, _strptime
missing module named errno.ENOENT - imported by errno, gettext
missing module named _functools.partial - imported by _functools, functools
missing module named _functools.reduce - imported by _functools, functools
missing module named copy.deepcopy - imported by copy, weakref, sets
missing module named exceptions.ReferenceError - imported by exceptions, weakref
missing module named binascii.hexlify - imported by binascii, random
missing module named math.sin - imported by math, random
missing module named math.sqrt - imported by math, random
missing module named math.cos - imported by math, random
missing module named math.acos - imported by math, random
missing module named math.ceil - imported by math, random
missing module named math.exp - imported by math, random
missing module named math.log - imported by math, random
missing module named math.e - imported by math, random
missing module named math.pi - imported by math, random
missing module named _ctypes.call_function - imported by _ctypes, pyreadline.console.console
missing module named _ctypes._wstring_at_addr - imported by _ctypes, ctypes
missing module named _ctypes._string_at_addr - imported by _ctypes, ctypes
missing module named _ctypes._cast_addr - imported by _ctypes, ctypes
missing module named _ctypes._memset_addr - imported by _ctypes, ctypes
missing module named _ctypes._memmove_addr - imported by _ctypes, ctypes
missing module named _ctypes.get_last_error - imported by _ctypes, ctypes
missing module named _ctypes.set_last_error - imported by _ctypes, ctypes
missing module named _ctypes._check_HRESULT - imported by _ctypes, ctypes
missing module named _ctypes.set_conversion_mode - imported by _ctypes, ctypes
missing module named _ctypes._pointer_type_cache - imported by _ctypes, ctypes
missing module named _ctypes.POINTER - imported by _ctypes, ctypes
missing module named _ctypes._SimpleCData - imported by _ctypes, ctypes
missing module named _ctypes.get_errno - imported by _ctypes, ctypes
missing module named _ctypes.set_errno - imported by _ctypes, ctypes
missing module named _ctypes.alignment - imported by _ctypes, ctypes
missing module named _ctypes.addressof - imported by _ctypes, ctypes
missing module named _ctypes.resize - imported by _ctypes, ctypes
missing module named _ctypes.byref - imported by _ctypes, ctypes
missing module named _ctypes.sizeof - imported by _ctypes, ctypes
missing module named _ctypes.dlopen - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_STDCALL - imported by _ctypes, ctypes
missing module named _ctypes.LoadLibrary - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_USE_ERRNO - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_USE_LASTERROR - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_PYTHONAPI - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_CDECL - imported by _ctypes, ctypes
missing module named _ctypes.FormatError - imported by _ctypes, ctypes
missing module named _ctypes.ArgumentError - imported by _ctypes, ctypes
missing module named _ctypes.RTLD_LOCAL - imported by _ctypes, ctypes
missing module named _ctypes.RTLD_GLOBAL - imported by _ctypes, ctypes
missing module named _ctypes.__version__ - imported by _ctypes, ctypes
missing module named _ctypes.CFuncPtr - imported by _ctypes, ctypes
missing module named _ctypes._Pointer - imported by _ctypes, ctypes
missing module named _ctypes.Structure - imported by _ctypes, ctypes
missing module named _ctypes.Array - imported by _ctypes, ctypes
missing module named _ctypes.Union - imported by _ctypes, ctypes
missing module named struct.calcsize - imported by struct, ctypes
missing module named pyreadline.console.ansi.AnsiWriter - imported by pyreadline.console.ansi, pyreadline.console.console
missing module named pyreadline.console.ansi.AnsiState - imported by pyreadline.console.ansi, pyreadline.console.console, pyreadline.console.ironpython_console
missing module named pyreadline.keysyms.KeyPress - imported by pyreadline.keysyms, pyreadline.console.console
missing module named pyreadline.keysyms.make_KeyPress - imported by pyreadline.keysyms, pyreadline.console.ironpython_console, pyreadline.console.console
missing module named pyreadline.keysyms.make_keyinfo - imported by pyreadline.keysyms, pyreadline.console.ironpython_console
missing module named pyreadline.keysyms.make_KeyPress_from_keydescr - imported by pyreadline.keysyms, pyreadline.console.ironpython_console
missing module named pyreadline.keysyms.make_keysym - imported by pyreadline.keysyms, pyreadline.console.ironpython_console
missing module named startup - imported by pyreadline.keysyms.common, pyreadline.keysyms.keysyms
missing module named System - imported by pyreadline.clipboard.ironpython_clipboard, pyreadline.keysyms.ironpython_keysyms, pyreadline.console.ironpython_console, pyreadline.rlmain
missing module named _scproxy._get_proxy_settings - imported by _scproxy, urllib `enter code here`
missing module named _scproxy._get_proxies - imported by _scproxy, urllib
missing module named _scproxy - imported by urllib
missing module named EasyDialogs.AskPassword - imported by EasyDialogs, getpass
missing module named EasyDialogs - imported by getpass
missing module named termios - imported by getpass
missing module named pwd - imported by posixpath, getpass
missing module named SOCKS - imported by ftplib
missing module named binascii.b2a_qp - imported by binascii, quopri
missing module named binascii.a2b_qp - imported by binascii, quopri
missing module named socket.getnameinfo - imported by socket, ssl
missing module named socket.error - imported by socket, ssl
missing module named socket.socket - imported by socket, ssl
missing module named socket._delegate_methods - imported by socket, ssl
missing module named socket._fileobject - imported by socket, ssl
missing module named _ssl.PROTOCOL_SSLv2 - imported by _ssl, ssl
missing module named _ssl.PROTOCOL_TLSv1 - imported by _ssl, ssl
missing module named _ssl.PROTOCOL_SSLv23 - imported by _ssl, ssl
missing module named _ssl.PROTOCOL_SSLv3 - imported by _ssl, ssl
missing module named _ssl.SSL_ERROR_EOF - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_WANT_WRITE - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_ZERO_RETURN - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_WANT_X509_LOOKUP - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_SSL - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_WANT_CONNECT - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_INVALID_ERROR_CODE - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_WANT_READ - imported by _ssl, ssl, socket
missing module named _ssl.SSL_ERROR_SYSCALL - imported by _ssl, ssl, socket
missing module named _ssl.RAND_status - imported by _ssl, ssl, socket
missing module named _ssl.RAND_egd - imported by _ssl, ssl, socket
missing module named _ssl.RAND_add - imported by _ssl, ssl, socket
missing module named _ssl.CERT_REQUIRED - imported by _ssl, ssl
missing module named _ssl.CERT_NONE - imported by _ssl, ssl
missing module named _ssl.CERT_OPTIONAL - imported by _ssl, ssl
missing module named _ssl.SSLError - imported by _ssl, ssl, socket
missing module named _ssl.OPENSSL_VERSION_NUMBER - imported by _ssl, ssl
missing module named _ssl.OPENSSL_VERSION_INFO - imported by _ssl, ssl
missing module named _ssl.OPENSSL_VERSION - imported by _ssl, ssl
missing module named rourl2path.url2pathname - imported by rourl2path, urllib
missing module named rourl2path.pathname2url - imported by rourl2path, urllib
missing module named rourl2path - imported by urllib
missing module named sys.py3kwarning - imported by sys, httplib
missing module named binascii.b2a_base64 - imported by binascii, email.base64mime
missing module named binascii.a2b_base64 - imported by binascii, email.base64mime
missing module named sys.stderr - imported by sys, smtplib
missing module named IronPythonConsole - imported by pyreadline.console.ironpython_console
missing module named clr - imported by pyreadline.clipboard.ironpython_clipboard, pyreadline.console.ironpython_console
missing module named errno.EINVAL - imported by errno, StringIO
missing module named cStringIO.StringIO - imported by cStringIO, gettext, pickle, pprint, socket, email.parser, email.message, tempfile, quopri, httplib, urllib, email.generator, email.iterators, shlex, encodings.uu_codec, encodings.quopri_codec
missing module named binascii.a2b_uu - imported by binascii, encodings.uu_codec
missing module named binascii.b2a_uu - imported by binascii, encodings.uu_codec
missing module named 'org.python'.PyStringMap - imported by 'org.python', pickle
missing module named 'org.python' - imported by pickle
missing module named _struct.__doc__ - imported by _struct, struct
missing module named _struct._clearcache - imported by _struct, struct
missing module named fcntl - imported by subprocess, tempfile
missing module named threading.RLock - imported by threading, _threading_local
missing module named threading.current_thread - imported by threading, _threading_local
missing module named traceback.format_exc - imported by traceback, threading
missing module named os.urandom - imported by os, random
missing module named riscosenviron._Environ - imported by riscosenviron, os
missing module named riscosenviron - imported by os
missing module named riscospath - imported by os
missing module named riscos._exit - imported by riscos, os
missing module named riscos - imported by os
missing module named ce._exit - imported by ce, os
missing module named ce - imported by os
missing module named _emx_link.link - imported by _emx_link, os
missing module named _emx_link - imported by os
missing module named os2._exit - imported by os2, os
missing module named os2 - imported by os
missing module named nt._isdir - imported by nt, ntpath
missing module named nt._getfullpathname - imported by nt, ntpath
missing module named nt._exit - imported by nt, os
missing module named posix._exit - imported by posix, os
missing module named posix - imported by os
missing module named resource - imported by posix
missing module named strop.whitespace - imported by strop, string
missing module named strop.maketrans - imported by strop, string
missing module named strop.lowercase - imported by strop, string
missing module named strop.uppercase - imported by strop, string
missing module named org.PyStringMap - imported by org, copy
missing module named org - imported by copy
missing module named re._compile - imported by re, sre
missing module named re.__all__ - imported by re, sre
missing module named codecs.mbcs_encode - imported by codecs, encodings.mbcs
missing module named codecs.mbcs_decode - imported by codecs, encodings.mbcs
Run Code Online (Sandbox Code Playgroud)
哇!搞了一个上午,终于发现问题了。
这被追溯到一个 dll - python27.dll。
我在朋友的机器上构建了该应用程序(他的机器是 2.7.10 版本),并在我的 pyinstaller 构建之上复制了这个 dll,从而替换了我的 dll(来自 2.7.3 版本),现在一切正常了。
我曾尝试复制许多其他可疑的 .dll,但是复制这个并且只有这个 dll 解决了问题。
随后,我将整个 python 安装更新到最新的 2.7.11,并构建了测试程序,最后根据需要打印出了 1e-07。
然后,在处理了通过更新所有这些(包括 pyinstaller)而产生的所有新问题后,我能够构建我的发布应用程序。
令人震惊和惊讶的是,Python 2.7.3 显然对 PyInstaller 生成的独立可执行文件存在此问题,但情况似乎确实如此。