Reputation: 3872
I'm trying to get a minimal example working using pyinstaller
and opencv
inside a conda
environment.
So far, what I'm doing is:
conda create -n minimal_example python=3 pyinstaller opencv
which leaves me with the following packages:
# Name Version Build Channel
altgraph 0.17 py_0
blas 1.0 mkl
ca-certificates 2020.1.1 0
certifi 2020.6.20 py38_0
future 0.18.2 py38_1
hdf5 1.10.4 h7ebc959_0
icc_rt 2019.0.0 h0cc432a_1
intel-openmp 2020.1 216
jpeg 9b hb83a4c4_2
libopencv 4.0.1 hbb9e17c_0
libpng 1.6.37 h2a8f88b_0
libtiff 4.1.0 h56a325e_1
lz4-c 1.9.2 h62dcd97_0
macholib 1.11 py_0
mkl 2020.1 216
mkl-service 2.3.0 py38hb782905_0
mkl_fft 1.1.0 py38h45dec08_0
mkl_random 1.1.1 py38h47e9c7a_0
numpy 1.18.5 py38h6530119_0
numpy-base 1.18.5 py38hc3f5095_0
opencv 4.0.1 py38h2a7c758_0
openssl 1.1.1g he774522_0
pefile 2019.4.18 py_0
pip 20.1.1 py38_1
py-opencv 4.0.1 py38he44ac1e_0
pycryptodome 3.8.2 py38he774522_0
pyinstaller 3.6 py38h62dcd97_5
python 3.8.3 he1778fa_0
pywin32 227 py38he774522_1
pywin32-ctypes 0.2.0 py38_1000
setuptools 47.3.1 py38_0
six 1.15.0 py_0
sqlite 3.32.3 h2a8f88b_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.16.27012 hf0eaf9b_2
wheel 0.34.2 py38_0
wincertstore 0.2 py38_0
xz 5.2.5 h62dcd97_0
zlib 1.2.11 h62dcd97_4
zstd 1.4.4 ha9fde0e_3
I have a script called minimal_build.py
with the following content:
print('Importing numpy')
import numpy as np
print(np.__version__)
print(np.__file__)
print('Importing OpenCV')
import cv2
I'm trying to package that script into an executable running
pyinstaller minimal_build.py
When running the resulting exe, I get the following output:
Importing numpy
C:\Users\me\Anaconda3\envs\minimal_example\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:623: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
exec(bytecode, module.__dict__)
Traceback (most recent call last):
File "minimal_build.py", line 10, in <module>
File "C:\Users\me\Anaconda3\envs\minimal_example\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\__init__.py", line 235, in <module>
File "C:\Users\me\Anaconda3\envs\minimal_example\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\mkl\__init__.py", line 54, in <module>
File "mkl\_mkl_service.pyx", line 27, in init mkl._py_mkl_service
ModuleNotFoundError: No module named 'six'
[9644] Failed to execute script minimal_build
So I'm guessing, that it tries to import numpy from my user folder instead of the package. What am I doing wrong?
Upvotes: 3
Views: 689
Reputation: 46
I happened to have the same problem as you
Here is the solution I tried:
conda create -n minimal_example python=3.7 pyinstaller
conda activate minimal_example
pip install opencv-python
not conda install opencv
my conda list:
# Name Version Build Channel
altgraph 0.17 py_0 defaults
ca-certificates 2020.1.1 0 defaults
certifi 2020.6.20 py37_0 defaults
future 0.18.2 py37_1 defaults
macholib 1.11 py_0 defaults
numpy 1.19.0 pypi_0 pypi
opencv-python 4.2.0.34 pypi_0 pypi
openssl 1.1.1g he774522_0 defaults
pefile 2019.4.18 py_0 defaults
pip 20.1.1 py37_1 defaults
pycryptodome 3.8.2 py37he774522_0 defaults
pyinstaller 3.6 py37h62dcd97_5 defaults
python 3.7.7 h81c818b_4 defaults
pywin32 227 py37he774522_1 defaults
pywin32-ctypes 0.2.0 py37_1000 defaults
setuptools 47.3.1 py37_0 defaults
sqlite 3.32.3 h2a8f88b_0 defaults
tqdm 4.46.1 py_0 defaults
vc 14.1 h0510ff6_4 defaults
vs2015_runtime 14.16.27012 hf0eaf9b_2 defaults
wheel 0.34.2 py37_0 defaults
wincertstore 0.2 py37_0 defaults
zlib 1.2.11 h62dcd97_4 defaults
then
pyinstaller -F path/to/your/python-file -p path/to/your/venv/python.exe
Upvotes: 3