I am relatively new to programming and I am using macOS Catalina 10.15.4 python 3.7 and pyinstaller3.6 to convert my python script to an executable. I manage to convert the script to an executable but when I click on it I get the following error:
issue:Traceback (most recent call last):
File "QC.py", line 2, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "cv2/__init__.py", line 5, in <module>
ImportError: dlopen(/Users/kapten42/Desktop/OCR/QA/dist/QC/cv2/cv2.cpython-37m-darwin.so, 2): Library not loaded: #loader_path/libpng16.16.dylib
Referenced from: /Users/kapten42/Desktop/OCR/QA/dist/QC/libfreetype.6.dylib
Reason: Incompatible library version: libfreetype.6.dylib requires version 54.0.0 or later, but libpng16.16.dylib provides version 38.0.0
[35604] Failed to execute script QC
I installed most of my packages using pip3 except for tesseract which I had to install using brew. I have been searching everywhere and really stumped with this one. I used brew to update libpng but the it didn't change anything. Below is the list of imports made at the top of my code. I am really stuck so any advice is greatly appreciated
from PIL import Image
import cv2
from skimage.filters import threshold_local
from skimage import io
import csv
import pytesseract
import re
import imutils
import numpy as np
from datetime import datetime
from spellchecker import SpellChecker
import json
import tempfile
import requests
import os
from pdf2image import convert_from_path
from dateutil.relativedelta import relativedelta
So I found a solution to the problem. Pyinstaller was pulling the wrong libpng16.16.dylib into the dist folder that was created. I used
brew install libpng
to get the latest version and then went to the folder
usr/local/cellar/libpng/1.6.37/lib
and copied libpng16.16.dylib and moved it to the dist folder and that resolved the issue.
Related
I'm currently trying to use a library written in C with my Python code but I didn't have much success at all. I'm currently using Windows and have downloaded, saved and installed the library (linked below) to a directory near my project using Cygwin.
As of now, I'm not sure how you load it within your Python code. I followed the instruction in this link: https://github.com/xiph/rnnoise/issues/69 but replaced the library path with a relative path and saved the library inside my project directory. Here's my code and here's the return error
import wave
import os,sys
import ctypes
import contextlib
import numpy as np
from ctypes import util
from scipy.io import wavfile
from pydub import AudioSegment
lib_path = "rnnoise"
lib = ctypes.cdll.LoadLibrary(lib_path)
Here's the version from the instruction:
import wave
import os,sys
import ctypes
import contextlib
import numpy as np
from ctypes import util
from scipy.io import wavfile
from pydub import AudioSegment
lib_path = util.find_library("rnnoise")
if (not("/" in lib_path)):
lib_path = (os.popen('ldconfig -p | grep '+lib_path).read().split('\n')[0].strip().split(" ")[-1] or ("/usr/local/lib/"+lib_path))
lib = ctypes.cdll.LoadLibrary(lib_path)
Traceback (most recent call last):
File "c:/Users/duyba/Documents/CET/Project/vadtest/noisetest.py", line 14, in <module>
lib = ctypes.cdll.LoadLibrary(lib_path)
File "C:\Users\duyba\anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\duyba\anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 1920] The file cannot be accessed by the system
My impression of the instruction version was that they are trying to locate the library in Linux, so I just copied the library to the project folder and didn't know what they are trying to load once the library is located. Also, I think that some environment pathway problems may be at play here since I downloaded and installed this library in Windows.
The library: https://github.com/xiph/rnnoise.
Thanks.
This could be an file access permission error. You might be able to get around it by making a new virtual environment or by uninstalling and reinstalling Python; see this post.
So I am stuck on how can I fix the import error for imresize. I installed all the things I needed like installing Pillow but I haven't been able to find a solution. Also the code that I trying to run is from this github link https://github.com/CSAILVision/IBD
Also side note I do not own this code nor was not the original arthor of it. This is for a research project that I am apart of. In addition I try asked the original arthor with a fix but haven't heard back from them at all.
Installing Pillow, Replacing with code: from scipy.misc.pilutil import imread, installing Pillow-3.3.1-cp27-cp27m-win32.whl, Unninstall Pil and installing Pillow, Reinstalling Pillow.
from util.image_operation import *
from PIL import Image
import numpy as np
from imageio import imresize, imread
from visualize.plot import random_color
from torch.autograd import Variable as V
import torch
I expect it to run but print out the image but it doesn't.
Traceback (most recent call last):
File "test.py", line 4, in <module>
from loader.model_loader import loadmodel
File "/home/joshuayun/Desktop/IBD/loader/model_loader.py", line 5, in <module>
from util.feature_operation import hook_feature, hook_grad
File "/home/joshuayun/Desktop/IBD/util/feature_operation.py", line 6, in <module>
from imageio import imresize, imread, imsave
ImportError: cannot import name 'imresize'
If you want to work with the code as is, i would recommend creating a new environment, and installing an old version of scipy (0.19.1 should do the trick). In your new environment, assuming you are using conda, do:
conda install scipy==0.19.1
If you use pip instead:
pip install scipy==0.19.1
Since scipy 1.3.0rc1 resize has been removed.
I had the same problem, I had scipy 1.4. I did the following and it worked -
pip install scipy==1.1.0
I have a simple Python program that tries to import cv2, but fails.
File "/home/userJB/HelloWorld.py", line 4, in <module>
import cv2
File "/home/userJB/srcMisc/Python-2.7.13/INSTALL/lib/python2.7/site-packages/cv2/__init__.py", line 7, in <module>
from . import cv2
ImportError: cannot import name cv2
Where should I start looking to resolve this? I have installed a local version on python on this machine. I have also installed openCV on this machine. I might not have fully installed openCV correctly. Do I need to do anything else to build/install a cv2 module?
I have installed matplotlib-1.5.0.win-amd64-py2.7 from sourcefourge.net after downloading and installing numpy using commandprompt by using pip: pip install numpy. But when I write the following code it Gives me error. Help me out.
Code:
from matplotlib.pylab import *
pylab.plot([1,2,3,4],[1,2,3,4])
pylab.show()
It gives me following error message:
Traceback (most recent call last):
File "C:\Python27\Lib\idlelib\1.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 124, in <module>
from matplotlib.rcsetup import (defaultParams,
File "C:\Python27\lib\site-packages\matplotlib\rcsetup.py", line 25, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "C:\Python27\lib\site-packages\matplotlib\fontconfig_pattern.py", line 25, in <module>
from pyparsing import Literal, ZeroOrMore, \
ImportError: No module named pyparsing
There is an easy and complete guide on the Matplotlib Website.
Try and follow this one.
refer to this answer of mine
https://stackoverflow.com/a/38618044/5334188
install numpy
pip install numpy
If you face installation issues for numpy, get the pre-built windows installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/ for your python version (python version is different from windows version).
numpy 32-bit: numpy-1.11.1+mkl-cp27-cp27m-win32.whl
numpy 64-bit: numpy-1.11.1+mkl-cp27-cp27m-win_amd64.whl
Later you require VC++ 9.0, then please get it from below link Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
Then install matplotlib using
pip install matplotlib
If you face errors, please download below from http://www.lfd.uci.edu/~gohlke/pythonlibs/, which will do the rest.
32-bit: matplotlib-1.5.3-cp27-cp27m-win32.whl
64-bit: matplotlib-1.5.3-cp27-cp27m-win_amd64.whl
works like charm
I'm having issues using these three together. I believe wand is not recognizing the ImageMagick libraries but I'm not sure.
Environment:
Python 3.5.1 :: Anaconda 4.0.0 (64-bit)
Windows 7
Set up instructions I took:
Installed ImageMagick-6.9.4-Q8 (x64) with the "C/C++ development
headers options checked. (Installed to C:\Program
Files\ImageMagick-6.9.4-Q8)
Set MAGICK_HOME envar C:\Program Files\ImageMagick-6.9.4-Q8
Installed wand from pip
My code:
import wand
...
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
...
Traceback:
Traceback (most recent call last):
File ".\pdf_convert.py", line 31, in <module>
ret = pdf2jpg(f, target_file, 2480)
File ".\pdf_convert.py", line 10, in pdf2jpg
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
AttributeError: module 'wand' has no attribute 'image'
From everything I've seen I've followed the right setup instructions. I am using the 64 bit version of ImageMagick with the 64 bit version of Anaconda. This was working with me before until I started using Anaconda (before I was using regular 32 bit Python and 32 bit ImageMagick.)
Is there something I'm missing? Why is wand not working correctly?
Try this
from wand.image import Image
with Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
pass
Is there something I'm missing? Why is wand not working correctly?
I believe it is working as expected, and the original architect did not intend to allow top-package-level shortcuts (i.e. import wand). This kinda makes sense as wand integrates to IM with ctypes, and does not attempt to resolve libraries during setup.py.
You can modify the package to include the module shortcuts your expecting by adding the following.
# wand/__init__.py
import api
import color
import compat
import display
import drawing
import exceptions
import font
import image
import resource
import sequence
import version
But I wouldn't recommend this. The from package.module import Class is a lot more cleaner.
If you are using PIL.Image as well then use:
from wand.image import Image as wand_image_Image
import PIL