pyinstaller, poppler, and other dependencies - python

I am a new developer, and probably well beyond my scope right now. I have made a script that uses several dependencies I had to install on my personal PC, and I cannot install them on my work PC. I know the code itself works as intended when I use it at home with all dependencies available. This is where I get beyond my scope as I do not know how to include these dependencies with my distribution version. I have used pyinstaller to attempt to "catch" the dependencies when compiling to a .exe, but to no avail.
Here is a snippet of my dependencies
import pytesseract
import sys
import tkinter as tk
import os
from PIL import Image
from tkinter import Button
from pdf2image import convert_from_path
from tkinter import filedialog
from tkinter import messagebox
from PIL import ImageTk as itk
poppler_path = r"D:\7-10\Receiver Reader V0.1\poppler\bin"
pytesseract.pytesseract.tesseract_cmd = r'D:\7-10\Receiver Reader V0.1\Tesseract-OCR\tesseract'
Here is the error I get on the work PC
Exception in Tkinter callback
Traceback (most recent call last):
File "site-packages\pdf2image\pdf2image.py", line 409, in pdfinfo_from_path
File "subprocess.py", line 854, in __init__
File "subprocess.py", line 1307, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tkinter\__init__.py", line 1883, in __call__
File "ReceiverReaderV1.py", line 69, in run_reader_prog
File "site-packages\pdf2image\pdf2image.py", line 89, in convert_from_path
File "site-packages\pdf2image\pdf2image.py", line 430, in pdfinfo_from_path
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
Any help is greatly appreciated,
Thank you!

Related

how use pyinstaller with opencv in raspbian?

i wrote this python script "mycv.py" in raspbian:
import cv2 as cv
and it debug and run currectly. then i use pyinstaller to make executable file.
but when run file in terminal. it has error:
Traceback (most recent call last):
File "mycv.py", line 1, in <module>
import cv2 as cv
File "/usr/local/lib/python3.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "cv2/__init__.py", line 89, in <module>
File "cv2/__init__.py", line 58, in bootstrap
File "cv2/__init__.py", line 56, in load_first_config
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
[28400] Failed to execute script mycv
Any help is appreciated
After lots of debugging, I found the following solution:
Get the path of OpenCV
import cv2
print(cv2.file) # /usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.so
Add this path while compiling through pyinstaller
pyinstaller main.py -n myApp --paths="/usr/local/lib/python3.6/dist-packages/cv2/python-3.6"
I hope this helps others also

Problem displaying widgets / ipywidgets install unsuccessful

I'm implementing widgets in my jupyter notebook (via anaconda). I tried first by using an old code from a professor of mine, but it's not displaying widgets.
I tried installing:
jupyter labextension install #jupyter-widgets/jupyterlab-manager
But it was unsuccessful
This was presented when I attempted installation of the package via windows command prompt:
C:\Users\davio>jupyter labextension install #jupyter-widgets/jupyterlab-manager
Traceback (most recent call last): File
"C:\Users\davio\Anaconda3\lib\site-packages\jupyterlab_server\server.py",
line 14, in
from notebook.base.handlers import ( File "C:\Users\davio\Anaconda3\lib\site-packages\notebook\base\handlers.py",
line 30, in
from tornado import web, gen, escape, httputil File "C:\Users\davio\Anaconda3\lib\site-packages\tornado\web.py", line 87,
in
from tornado.httpserver import HTTPServer File "C:\Users\davio\Anaconda3\lib\site-packages\tornado\httpserver.py",
line 29, in
import ssl File "C:\Users\davio\Anaconda3\lib\ssl.py", line 98, in
import _ssl # if we can't import it, let the error propagate ImportError: DLL load failed: The specified procedure could
not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\davio\Anaconda3\Scripts\jupyter-labextension-script.py",
line 6, in
from jupyterlab.labextensions import main File "C:\Users\davio\Anaconda3\lib\site-packages\jupyterlab\labextensions.py",
line 16, in
from .commands import ( File "C:\Users\davio\Anaconda3\lib\site-packages\jupyterlab\commands.py",
line 27, in
from jupyterlab_server.process import which, Process, WatchHelper File
"C:\Users\davio\Anaconda3\lib\site-packages\jupyterlab_server__init__.py",
line 4, in
from .app import LabServerApp File "C:\Users\davio\Anaconda3\lib\site-packages\jupyterlab_server\app.py",
line 9, in
from .server import ServerApp File "C:\Users\davio\Anaconda3\lib\site-packages\jupyterlab_server\server.py",
line 26, in
from jupyter_server.base.handlers import ( # noqa ModuleNotFoundError: No module named 'jupyter_server'
I expect to:
i) Be able to install all the required ipy packages in order to display widgets properly
ii) View and manipulate widgets properly
Thank you!!!!
Maybe if you had alredy python installed before installing anaconda, that's the problem. Try uninstalling python and only working with anaconda's python, that worked for me.
(Sorry for bad english)

Getting audio from a URL and playing it

There is a link to an mp3 file that needs to be streamed from a URL like http://example.com/music_radio.mp3 and played on a computer. On the Internet, although there are examples of streaming audio, but they are mainly for Python2, and for Python3 there are no such libraries anymore, I tried to do it this way:
import vlc
p = vlc.MediaPlayer ("http://example.com/music_radio.mp3")
p.play ()
But it constantly displays an error:
Traceback (most recent call last): File "PythonProjects / URL /
main.py", line 2, in import vlc File "PythonProjects / URL / venv /
lib / python3.6 / site-packages / vlc / init.py", line 3, in public
import ModuleNotFoundError: No module named 'public'
And the problem is that the public module is not installed. How can you solve this problem or how else can you receive and play audio by reference?
UPD: That link suggests either non-working code, or code using Python2, not Python3
UPD2: When using python-vlc, this error occurs:
Traceback (most recent call last): File
"PythonProjects/URL/main.py", line 4, in
import vlc File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py",
line 203, in
dll, plugin_path = find_lib() File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py",
line 194, in find_lib
ctypes.CDLL('libvlccore.dylib') File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/init.py",
line 348, in init
self._handle = _dlopen(self._name, mode) OSError: dlopen(libvlccore.dylib, 6): image not found
If this can help
from IPython.display import Audio
Audio(url="http://www.nch.com.au/acm/8k16bitpcm.wav")

Pygame installed, but not working

I am using a mac and i want to use pygame but it is not working.
this is the error i get when I try to do import pygame
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
Please help I am using python 2.7.9
If your file name is called pygame.py the system imports your python file.
If your file name is not pygame.py, you can try doing pip install pygame or python -m install pygame.

ImportError: No module named FileDialog - after PyInstaller

I have written a program that I have tried to turn into an executable using PyInstaller. Pyinstaller appears to have finished without any errors and I end up with an application in /dist/my_program. However, when I try to run that application a console window flashes up for a second with a traceback:
Edit: I have copied the traceback out. There may be a mistake as I had to type it up from a screenshot because it only flashes up.
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module
ImportError: No module named FileDialog
Below are the imports that I have in my code:
import Tkinter
from tkFileDialog import askopenfilename
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import subprocess
from PIL import Image, ImageTk
import os
Does anyone know whats causing this/what the fix is? I presume the error is the importation of tkFileDialog?
Edit2: the program runs fine when I run it in my interpreter (Spyder) but when I packaged it using PyInstaller the resulting application gives this error.
According to this question adding import FileDialog solves the problem. Matplotlib seems to need this.
However, I've used Pyinstaller on a script of mine also importing matplotlib and it gives no such error. So I don't know what exacly is the problem here.

Categories

Resources