Scikit-image: cannot import name 'label' - python

I have some scripts that use skimage.measure.label. On my old laptop (Debian 7, Python 2) these scripts worked perfectly. Recently, when I got a new laptop, I moved to Debian 8 and Python 3. Now these scripts cannot import skimage.measure.label:
File "image_converter.py", line 8, in <module>
from skimage.measure import label
ImportError: cannot import name 'label'
All of the other imports are working fine:
from skimage import data
from skimage.filter import threshold_otsu
from skimage.segmentation import clear_border
from skimage.morphology import closing, square
from skimage.measure import regionprops
from skimage.color import label2rgb
import skimage.io as ski_io
pip3 list says:
(...)
scikit-image (0.9.3)
(...)
Python version is 3.4.3.
What has happened there? Has scikit-image (re-)moved measure.label?
In the official documentation it is still listed: skimage.measure.label

There is indeed no function label in module measure for release 0.9 (see http://scikit-image.org/docs/0.9.x/api/skimage.measure.html).
Basically, you should update your version of skimage. The most recent version is 0.12.3. Python 3.4 is officially tested against, so you shouldn't expect any troubles with compatibility.

Related

Why is the import failing while implementing OpenVino on Colab notebook?

import cv2
import numpy as np
from utils.opv import OpvModel,OpvExec
Import Error: cannot import name 'IEPlugin' from 'openvino.inference_engine' (/usr/local/lib/python3.7/dist-packages/openvino/inference_engine/init.py)
The error is associated with int.py and opv.py files used
IEPlugin class has been deprecated since OpenVINO 2021.1 release. Use IECore instead.

Is there a way to import an older version of tensor flow to use in python?

I keep getting this error when running my python 3.8 code:
AttributeError: module 'tensorflow._api.v2.train' has no attribute 'SessionRunHook'
I previously read that this is because the tensorflow version is not correct. How do I use a different version of tensorflow?
I have tried:
import tensorflow as tf
tf.compat.v1.disable_v2_behavior()
print(tf.__version__)
but it still shows that I am using tensorflow version 2.5.0.
I have also tried
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import argparse
import os
import pandas as pd
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
import tensorflow.compat.v1 as tf
tf.compat.v1.disable_v2_behavior()
print(tf.__version__)
import numpy as np
from dltk.networks.regression_classification.resnet import resnet_3d
from dltk.io.abstract_reader import Reader
The attribute error seems to appear at the last line when I try to import dltk.io.abstract_reader.
You can uninstall the package and install an older version. The grammar is like pip install tensorflow==<version>.
If you would like to keep the two versions at the same time, I'm afraid you should use anaconda.

Python ImportError: cannot import name '__version__'

Below code is part of my code
import time
import matplotlib
import matplotlib.pylab as plt
plt.rcParams["axes.grid"] = False
import mmcv
from mmcv.runner import load_checkpoint
import mmcv.visualization.image as mmcv_image
def imshow(img, win_name='', wait_time=0): plt.figure(
figsize=(50, 50)); plt.imshow(img)
mmcv_image.imshow = imshow
from mmdet.models import build_detector
from mmdet.apis import inference_detector, show_result, init_detector
and this part has an error
from mmcv.runner import load_checkpoint
error is like below
from PIL import Image, ImageOps, ImageEnhance, __version__ as PILLOW_VERSION
ImportError: cannot import name '__version__'
but I have already executed pip install Pillow, please is anyone could help me...
The problem was due to version issues as discussed in this Github issue
Can you try the following?
pip install Pillow==6.1
Also, removing and reinstalling Pillow might help.

How to Import Image from PILLOW In Jupyter?

I am trying to import Image from PILLOW.
from PILLOW import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
Undefined function 'from' for input arguments of type 'char'.
>> import PIL.Image
im = Image.open("bride.jpg")
im.rotate(45).show()
Error using import
Import argument 'PIL.Image' cannot be found or cannot be imported.
Undefined function 'from' for input arguments of type 'char'.
I keep getting the same error. Am I using the wrong import statement?
EDIT:
I noticed something else. when i browse through my C:/ drive and look inside the folders where Pip, and PIL ,etc is. There is nothing inside them. Even when i copy a file with stuff to that area, and open that new file, i cant see any of the stuff inside. When i copy it though, and the green bar goes it shows data being transferred.
The Code:
https://hub.gke.mybinder.org/user/alexmill-website_notebooks-fcqkeh7a/notebooks/fourier-spinning-circles.ipynb#
Example:
enter code here
from PIL import Image, ImageEnhance
# Main imports/Initialization
%matplotlib inline
import matplotlib
from matplotlib import animation, rc
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
from IPython.display import HTML
import numpy as np
from PIL import Image, ImageEnhance
import requests
from io import BytesIO
from copy import deepcopy
from scipy.spatial import distance
from scipy.interpolate import UnivariateSpline
from copy import deepcopy
​
# Default figure size in notebook
matplotlib.rcParams['figure.figsize'] = (6,6)
matplotlib.rcParams['image.aspect'] = 'equal'
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-16-7c75157a7886> in <module>
7 from IPython.display import HTML
8 import numpy as np
----> 9 from PIL import Image, ImageEnhance
10 import requests
11 from io import BytesIO
ModuleNotFoundError: No module named 'PIL'
The reason your binder doesn't work is because your requirements.txt looks like this:
matplotlib==2.0.2
requests==2.20.0
Pillow==5.0.0
numpy==1.13.0
scipy==0.19.0
pandas==0.20.2
scikit-learn==0.18.1
tzlocal-1.5.1
This line:
tzlocal-1.5.1
Probably breaks the binder dependency install. Another thing is that these are very specific versions that might generate too specific dependencies (ref. here). I recommend changing it to this:
matplotlib
requests
pillow
numpy
scipy
pandas
scikit-learn
tzlocal
At least your binder started working when I did that.
Locally you will just have to run pip install -r requirements.txt with an admin command prompt and then your local Jupyter installation should automatically work, at least it did when I cloned your notebook to a Windows VM.

Windows Python 2.7 wxwidgets and 'gizmos'

Can anyone give me precise instructions on how to access the wx 'gizmos' module?
import wx.gizmos
ImportError: No module named gizmos
The code in question has this:
import wx
import string
import wx.gizmos
from wx.lib.mixins import treemixin
import Descriptor
'pip list' reports
wxPython-Phoenix (3.0.3.dev1830+0b5f910)
Do I have the right package installed? I should add that these files are present:
\python27\Lib\wxpython\wx-3.0-msw\wx\gizmos.py
\python27\Lib\wxpython\wx-3.0-msw\wx\_gizmos.pyd
[edit] For clarification, this seems to be OK so I'm reasonably sure the WX module is installed correctly.
import wx
import copy
# had to add .agw to get this to load
import wx.lib.agw.customtreectrl as CT
import DescriptorDetailsPanel
TAIA
Congrats, you have two installs of wx. You can use pkg_resources to get the one you want. Put the following at the top of the script:
__requires__ = ["wx >= 3.0"]
import pkg_resources
This will tell pkg_resources to set things up so that a version of wx of at least 3.0 will be available if you import wx rather than the default 2.x.
You can try to remove wxpython from pip install and reinstall wxpython from this site:
https://www.wxpython.org/download.php
It worked for me!

Categories