How to use pyinstaller with pipenv / pyenv

2024/10/11 18:26:05

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 runrun_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_buildPyInstaller.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 mainbuild(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 buildexec(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 assembleself._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_libraryraise 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

Answer

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://en.xdnf.cn/q/69745.html

Related Q&A

Sending DHCP Discover using python scapy

I am new to python and learning some network programming, I wish to send an DHCP Packet through my tap interface to my DHCP server and expecting some response from it. I tried with several packet build…

cnf argument for tkinter widgets

So, Im digging through the code here and in every class (almost) I see an argument cnf={} to the constructor, but unless Ive missed it, it is not explicitly stated what cnf is / expected to contain. Ca…

python exceptions.UnicodeDecodeError: ascii codec cant decode byte 0xa7 in

I am using scrapy with python and I have this code in a python item piplinedef process_item(self, item, spider):import pdb; pdb.set_trace()ID = str(uuid.uuid5(uuid.NAMESPACE_DNS, item[link]))I got this…

Trace Bug which happends only sometimes in CI

I have a strange bug in python code which only happens sometimes in CI.We cant reproduce it.Where is the test code:response=self.admin_client.post(url, post) self.assertEqual(200, response.status_code,…

Limit neural network output to subset of trained classes

Is it possible to pass a vector to a trained neural network so it only chooses from a subset of the classes it was trained to recognize. For example, I have a network trained to recognize numbers and l…

Unable to fully remove border of PyQt QGraphicsView

I have tried calling self.setStyleSheet("background: transparent; border: transparent;") on a QGraphicsView, but it still leaves a 1 pixel border on the top edge. I have also tried replacing …

SqlAlchemy non persistent column

I am trying to define a model using sqlalchemy such that one of the columns i only need in memory for processing, i do not have a corresponding database column for that. I need it such that when i save…

Creating command line alias with python

I want to create command line aliases in one of my python scripts. Ive tried os.system(), subprocess.call() (with and without shell=True), and subprocess.Popen() but I had no luck with any of these me…

Remove unwanted lines in captcha text - opencv - python

I trying to get text from captcha image using opencv. Problem is text are masked with noise and it is complex to process with those horizontal line/noise.Original imageMy processed image :not sure how …

Double Summation in Python

I am trying to write a code to conduct a double summation (see pic) in which; M is the subjects, N is the Trials, Yijt is the measured wave form data (3d array)so far I have; Given Y is the data arra…