How to use pyinstaller with pipenv / pyenv

寵の児 提交于 2020-08-02 05:06:27

问题


I am trying to ship an executable from my python script which lives inside a virtual environment using pipenv which again relies on pyenv for python versioning. For that, I want to us pyinstaller.

What I did:

pipenv install pyinstaller 
pyinstaller --onefile my_script.py

Output:

40 INFO: PyInstaller: 3.5
40 INFO: Python: 3.6.9
41 INFO: Platform: Linux-4.15.0-65-generic-x86_64-with-debian-stretch-sid
42 INFO: wrote /home/matthaeus/cybathlon/planvec/qt_video_gui_example.spec
44 INFO: UPX is not available.
45 INFO: Extending PYTHONPATH with paths
['/home/matthaeus/cybathlon/planvec', '/home/matthaeus/cybathlon/planvec']
45 INFO: checking Analysis
45 INFO: Building Analysis because Analysis-00.toc is non existent
45 INFO: Initializing module dependency graph...
46 INFO: Initializing module graph hooks...
47 INFO: Analyzing base_library.zip ...
2786 INFO: running Analysis Analysis-00.toc
2801 INFO: Caching module hooks...
2805 INFO: Analyzing /home/matthaeus/cybathlon/planvec/qt_video_gui_example.py
3284 INFO: Processing pre-find module path hook   distutils
3285 INFO: distutils: retargeting to non-venv dir '/home/matthaeus/.pyenv/versions/3.6.9/lib/python3.6/distutils/__init__.py'
3972 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
4336 INFO: Processing pre-find module path hook   site
4337 INFO: site: retargeting to fake-dir '/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/fake-modules'
6327 INFO: Loading module hooks...
6328 INFO: Loading module hook "hook-numpy.core.py"...
6458 INFO: Loading module hook "hook-sysconfig.py"...
6464 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
6534 INFO: Loading module hook "hook-scipy.py"...
6535 INFO: Loading module hook "hook-PyQt5.py"...
6549 WARNING: Hidden import "sip" not found!
6549 INFO: Loading module hook "hook-pkg_resources.py"...
6788 INFO: Processing pre-safe import module hook   win32com
7015 INFO: Loading module hook "hook-numpy.py"...
7015 INFO: Loading module hook "hook-cv2.py"...
7016 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
7048 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
7096 INFO: Loading module hook "hook-pydoc.py"...
7097 INFO: Loading module hook "hook-xml.py"...
7150 INFO: Loading module hook "hook-encodings.py"...
7203 INFO: Loading module hook "hook-setuptools.py"...
7423 WARNING: Hidden import "distutils.command.build_ext" not found!
7680 INFO: Looking for ctypes DLLs
7762 INFO: Analyzing run-time hooks ...
7769 INFO: Including run-time hook 'pyi_rth_pyqt5.py'
7770 INFO: Including run-time hook 'pyi_rth_pkgres.py'
7771 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
7785 INFO: Looking for dynamic libraries
9784 INFO: Looking for eggs
9784 INFO: Python library not in binary dependencies. Doing additional searching...
Traceback (most recent call last):
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/bin/pyinstaller", line 8, in <module>
    sys.exit(run())
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 844, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 791, in build
    exec(code, spec_namespace)
  File "/home/matthaeus/cybathlon/planvec/qt_video_gui_example.spec", line 17, in <module>
    noarchive=False)
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 243, in __init__
    self.__postinit__()
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/building/datastruct.py", line 158, in __postinit__
    self.assemble()
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 575, in assemble
    self._check_python_library(self.binaries)
  File "/home/matthaeus/.local/share/virtualenvs/planvec-R86NQhbu/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 681, in _check_python_library
    raise IOError(msg)
OSError: Python library not found: libpython3.6mu.so.1.0, libpython3.6m.so, libpython3.6m.so.1.0, libpython3.6.so.1.0
This would mean your Python installation doesn't come with proper library files.
This usually happens by missing development package, or unsuitable build parameters of Python installation.

* On Debian/Ubuntu, you would need to install Python development packages
  * apt-get install python3-dev
  * apt-get install python-dev
* If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)

I tried the recommended python3-dev and python-dev installations without luck. Now, I hope someone can enlighten me what is going on here!

Cheers, Matt


回答1:


You need to build with CPython shared-library enabled.

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.9
eval "$(pyenv init -)"

Reference: https://github.com/pyenv/pyenv/wiki



来源:https://stackoverflow.com/questions/58548730/how-to-use-pyinstaller-with-pipenv-pyenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!