pyinstaller可执行文件上的Python unicode错误

pyinstaller可执行文件上的Python unicode错误,python,shared-libraries,pyinstaller,dlopen,Python,Shared Libraries,Pyinstaller,Dlopen,我使用的是python版本2.7.15(由virtualenv生成),在通过pyinstaller将使用此python的python代码转换为可执行形式时遇到了问题。以下是pyinstaller无法构建的简单可复制程序: hi.py print("hi") 我运行以下命令来仔细检查它是否与python一起工作: ❯ $PY/bin/python hi.py hi 所以我尝试安装它: ❯ $PY/bin/pyinstaller hi.py --debug 543 INFO: PyInstall

我使用的是python版本2.7.15(由virtualenv生成),在通过pyinstaller将使用此python的python代码转换为可执行形式时遇到了问题。以下是pyinstaller无法构建的简单可复制程序:

hi.py

print("hi")
我运行以下命令来仔细检查它是否与python一起工作:

❯ $PY/bin/python hi.py
hi
所以我尝试安装它:

❯ $PY/bin/pyinstaller hi.py --debug
543 INFO: PyInstaller: 3.3.1
543 INFO: Python: 2.7.15
544 INFO: Platform: Linux-3.10.0-327.36.3.el7.x86_64-x86_64-with-redhat-7.2-Maipo
547 INFO: wrote /.../hi.spec
565 INFO: UPX is not available.
567 INFO: Extending PYTHONPATH with paths
['my_current_directory',
 'my_current_directory']
567 INFO: checking Analysis
605 INFO: checking PYZ
608 INFO: checking PKG
609 INFO: Bootloader /.../python2-rhel6/lib/python2.7/site-packages/PyInstaller/bootloader/Linux-64bit/run_d
609 INFO: checking EXE
611 INFO: checking COLLECT
3736 INFO: Building COLLECT out00-COLLECT.toc
4918 INFO: Building COLLECT out00-COLLECT.toc completed successfully.
运行它会产生错误:

❯ ./dist/hi/hi
[179215] PyInstaller Bootloader 3.x
[179215] LOADER: executable is /my_current_directory/dist/hi/hi
[179215] LOADER: homepath is /my_current_directory/dist/hi
[179215] LOADER: _MEIPASS2 is NULL
[179215] LOADER: archivename is /my_current_directory/dist/hi/hi
[179215] LOADER: Extracting binaries
[179215] LOADER: Executing self as child
[179215] LOADER: set _MEIPASS2 to /my_current_directory/dist/hi
[179215] LOADER: LD_LIBRARY_PATH_ORIG=/lib/
[179215] LOADER: LD_LIBRARY_PATH=/my_current_directory/dist/hi:/lib/
[179216] PyInstaller Bootloader 3.x
[179216] LOADER: executable is /my_current_directory/dist/hi/hi
[179216] LOADER: homepath is /my_current_directory/dist/hi
[179216] LOADER: _MEIPASS2 is /my_current_directory/dist/hi
[179216] LOADER: archivename is /my_current_directory/dist/hi/hi
[179216] LOADER: Already in the child - running user's code.
[179216] LOADER: Python library: /my_current_directory/dist/hi/libpython2.7.so.1.0
[179216] LOADER: Loaded functions from Python library.
[179216] LOADER: Manipulating environment (sys.path, sys.prefix)
[179216] LOADER: sys.prefix is /my_current_directory/dist/hi
[179216] LOADER: Setting runtime options
[179216] LOADER: Initializing python
[179216] LOADER: Overriding Python's sys.path
[179216] LOADER: Post-init sys.path is /my_current_directory/dist/hi
[179216] LOADER: Setting sys.argv
[179216] LOADER: setting sys._MEIPASS
[179216] LOADER: importing modules from CArchive
[179216] LOADER: extracted struct
[179216] LOADER: callfunction returned...
[179216] mod is NULL - structTraceback (most recent call last):
  File "/.../python-2.7-rhel6.8/lib/python2.7/struct.py", line 1, in <module>
    from _struct import *
ImportError: /my_current_directory/dist/hi/_struct.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
[179216] LOADER: extracted pyimod01_os_path
[179216] LOADER: callfunction returned...
[179216] LOADER: extracted pyimod02_archive
[179216] LOADER: callfunction returned...
[179216] mod is NULL - pyimod02_archiveTraceback (most recent call last):
  File "/tmp/pip-install-l80u_7/pyinstaller/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
ImportError: No module named struct
[179216] LOADER: extracted pyimod03_importers
[179216] LOADER: callfunction returned...
[179216] mod is NULL - pyimod03_importersTraceback (most recent call last):
  File "/tmp/pip-install-l80u_7/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
ImportError: No module named pyimod02_archive
[179216] LOADER: Installing PYZ archive with Python modules.
[179216] LOADER: PYZ archive: out00-PYZ.pyz
[179216] LOADER: LC_CTYPE was C but resulted in NULL FileSystemDefaultEncoding
[179216] LOADER: Setting FileSystemDefaultEncoding to ANSI_X3.4-1968 (was NULL)
[179216] LOADER: Running pyiboot01_bootstrap.py
Traceback (most recent call last):
  File "site-packages/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ImportError: No module named pyimod03_importers
[179216] Failed to execute script pyiboot01_bootstrap
[179216] LOADER: OK.
[179216] LOADER: Cleaning up Python interpreter.
[179215] LOADER: Back to parent (RC: 255)
[179215] LOADER: Doing cleanup
[179215] LOADER: Freeing archive status for /my_current_directory/dist/hi/hi
在s。但是,我不能,因为我没有删除它和删除它的权限,和/或使用另一个可以支持pyinstaller的python。因此我查看了
\u结构。因此

❯ ls -la _struct.so
-rwxr-xr-x 1 ... 101964 May 11 09:05 _struct.so
不是符号链接。Pyinstaller在某处复制了这个。在
$PY
中找不到它,在
lib64
中也找不到它

我的一个观察是:

在my
$PY
s python中:

>>> import sys
>>> print(sys.maxunicode)
65535
在其他蟒蛇中,我有:

>>> import sys
>>> print(sys.maxunicode)
1114111

这可能是unicode不匹配的原因之一。我有点不知所措——有人知道可能是什么问题吗?

阅读本书的“Unicode字符集”一节可能会有兴趣
>>> import sys
>>> print(sys.maxunicode)
1114111