pyinstaller打包py遇到的问题

遇到了几个问题,记录一下

ubuntu16.04系统 python3.6 conda (注意ubuntu的可执行文件就直接是文件名,windows的可执行文件是exe)

pip install pyinstaller

然后直接

pyinstaller -F 文件名.py

在当前目录下面有一个dist文件夹 直接运行./文件名即可

结果在运行的时候出现问题

Traceback (most recent call last):
  File "site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 13, in 
  File "/home/xx/anaconda3/envs/keras/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages/pkg_resources/__init__.py", line 86, in 
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
[132693] Failed to execute script pyi_rth_pkgres

有文章要降setuptools版本,或者升级
都对我无效
我是卸载了pip上的pyinstaller,改在conda环境里安装pyinstaller,结果出现了


Traceback (most recent call last):
  File "xx.py", line 6, in <module>
  File "/home/xx/anaconda3/envs/keras/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages/numpy/__init__.py", line 151, in <module>
  File "/home/xx/anaconda3/envs/keras/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages/numpy/ctypeslib.py", line 369, in <module>
  File "site-packages/numpy/ctypeslib.py", line 358, in _get_typecodes
  File "site-packages/numpy/ctypeslib.py", line 358, in <dictcomp>
ModuleNotFoundError: No module named 'numpy.core._dtype_ctypes'

解决办法参考链接
先将.py文件转换为.spec

pyi-makespec --noupx -F --hidden-import=numpy.core._dtype_ctypes 文件名.py

再生成可执行文件

pyinstaller 文件名.spec

搞定!

你可能感兴趣的:(服务器)