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
Related
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.
I am trying to import image to python but end up getting the same error again and again.
I have tried most of the solutions mentioned about this problem on multiple discussion threads but none of them have solved this issue of mine.
I have installed Pillow but still the error prevails. Would really appreciate some guidance on how to resolve this issue.
from scipy.misc import imread, imresize, imsave
import numpy as np
ImportError Traceback (most recent call last)
<ipython-input-6-c8bc16b68368> in <module>
----> 1 from scipy.misc import imread, imresize, imsave
2 import numpy as np
ImportError: cannot import name 'imread'
The library you're looking scipy.misc.imread is deprecated. You can use imageio. First install Pillow and then install imageio
pip install Pillow imageio
Then you can use,
imageio.imread('image1.png')
imageio.imread('image2.png', array)
But you cannot resize in imageio. Use numpy for that.
What is your version? I think scipy.misc.imread is deprecated. Use imageio
import imageio
image = imageio.imread('pic.png')
I came across an ImportError in the importing of matplotlib.pyplot on Windows 10 Pro
Here is the full error:
Traceback (most recent call last):
File "C:\Users\****\Dropbox\Code\Python\lib_test.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\pyplot.py", line 31, in <module>
import matplotlib.colorbar
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\artist.py", line 16, in <module>
from .path import Path
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\path.py", line 21, in <module>
from . import _path, rcParams
ImportError: cannot import name '_path'
Here is the script:
import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()
If anyone could help me, much appreciated.
It can be a problem related to matplotlib version. I had the same problem and solved it uninstalling the existing version of matplotlib (in my case with conda but the command is similar substituing pip to conda) so:
firstly uninstalling with:
conda uninstall matplotlib (or pip uninstall matplotlib)
and after the successful removal of the existing version (mine was 2.2.2), the following command installed a successive version, that can be specified with '==' after the module name:
conda install matplotlib==3.0.2 (or pip install matplotlib==3.0.2)
and the error disappears.
The uninstall command removed also seaborn installation so it was necessary to install it after matplotlib but it was easy...
Yeah!:)
Since you're probably like me and doing a lot of installing/importing, it can be just a mishap in the original matplotlib install... so try doing the ol' get out, walk around to the back side and give it a kick...
conda uninstall matplotlib
#let it do its thing
conda install matplotlib
#let it do its thing
Then test it on the code you're trying to do and see if it works. In my case, it came down to a "_Path" issue in my original install that messed up things. After the uninstall/install, I was fine.
Dunno what mpip is,, or why,, try plain old pip (or in your case perhaps pip3 ? This may have more to do with how the base Python was installed though,, why I suggest using Anaconda to install all (which automatically installs MPL as well..)
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
As far as I can tell, I don't even need pytz for what I'm doing.
I'm re-learning python for image processing using the O'Reilly book 'Programming Computer Vision with Python' for work (and I'm also new to mac, so on both counts I apologise if this is a stupid question).
Along with a 'empire.jpg' picture, I'm trying to run the script on page 16 which goes as follows:
from PIL import Image
from pylab import *
# read image to array
im = array(Image.open('empire.jpg')) # plot the image
imshow(im)
# some points
x = [100,100,400,400]
y = [200,500,200,500]
# plot the points with red star-markers
plot(x,y,'r*')
# line plot connecting the first two points
plot(x[:2],y[:2])
# add title and show the plot
title('Plotting: "empire.jpg"')
show()
but I get the following output with an error:
File "plotch1.py", line 2, in <module>
from pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py", line 208, in <module>
from matplotlib import mpl # pulls in most modules
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mpl.py", line 4, in <module>
from matplotlib import axes
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 18, in <module>
from matplotlib import dates as mdates
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/dates.py", line 82, in <module>
import pytz
ImportError: No module named pytz
I'm using OS X 10.9.4.
I've installed matplotlib and numpy from macpython.org and I've installed scipy 0.11.0 all for python 2.5.
Do I even need pytz? If not, how can I get around this error?
pylab requires pytz.
The easiest way to install a package in Python is to run pip install pytz.
Today, Python comes with pip pre-installed, but use these instructions if you need to install it: Installation: Do I need to install pip?
Firstly if you have installed pip then remove it by deleting the folder of pip inside python directory. Then install pip by this command:
$ sudo easy_install pip
Then you need to install pytz again by this command:
$ sudo pip install pytz
Don't update pip to 10th version because it might contain bugs which is causing problems.