imageio: AttributeError: 'module' object has no attribute 'imread' - python

I come up with the error AttributeError: 'module' object has no attribute 'imread' while using the imageio module with the following code. I searched the community a lot but all of the errors about imread command are discussed under scipy, but nothing for imageio. So, any comments or links are appreciated! Here is my code:
import os
import imageio
os.chdir('C:/concent')
png_dir='gif/'
images=[]
for file_name in os.listdir(png_dir):
if file_name.endswith('.png'):
file_path = os.path.join(png_dir, file_name)
images.append(imageio.imread(file_path))
imageio.mimsave('gif/movie.gif', images)

Probably you have another file named imageio.py in the working directory.
The import statement will import files from the current directory before searching standard library and site package locations.
You should be able to fix the problem by renaming your local imageio.py file to something else that does not clash with other modules.

Related

AttributeError: module 'numpy' has no attribute 'asarray'

I am using the Spyder IDE via Anaconda but the Numpy asarray method won't work.
from PIL import Image
import numpy as np
im = Image.open("photo.jpg", "r")
data = np.asarray(im)
print(data)
Based similar questions it is recommended to make sure there is no other file called numpy.py in the current directory, but I have checked and the only files are this .py and the image referenced.

ImportError: No module named X, even if folder is in the same directory

I've downloaded pymumble from https://github.com/Robert904/pymumble and saved it to my working directory. I import it with:
from pymumble import pymumble
However, I receive:
ImportError: No module named pymumble
I'm looking at similar code that does this successfully. What am I doing wrong when trying to import this?
As I can see there is no file called pymumble in given repository, if you are looking for this there is a file called mumble.py, try importing
from mumble import mumble
this will work.

How to create custom module with existing python module name and import that system module in the custom module

For example:
shutil is default python module
I have created custom python file called shutil.py and below is the code in that shutil.py file
import shutil
shutil.move('test.py', 'test/test.py')
It returned below error instead of calling python shutil module which was imported in this shutil.py file
AttributeError: 'module' object has no attribute 'move'
Please help me in this
Thanks
I suggest you to rename the import with as keyword
You need to move your line down like so:
import shutil
shutil.move('test.py', 'test/test.py')

How do I find the location of Python module sources while I can not import it?

The answer in How do I find the location of Python module sources? says just import it and print its __file__. But my question is that I cannot import a library cv2 while it returns ImportError: libcudart.so.7.5: cannot open shared object file: No such file or directory, so I cannot get its __file__ too. I want to find where does Python import this library so that I can check what is wrong with the library.
Try:
import imp
imp.find_module('cv2')

Python PIL has no attribute 'Image'

I'm using python2.6 and got a problem this morning. It said 'module' has no attribute 'Image'. Here is my input. Why the first time I can not use PIL.Image?
>>> import PIL
>>> PIL.Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Image'
>>> from PIL import Image
>>> Image
<module 'PIL.Image' from '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'>
>>> PIL.Image
<module 'PIL.Image' from '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'>
PIL's __init__.py is just an empty stub as is common. It won't magically import anything by itself.
When you do from PIL import Image it looks in the PIL package and finds the file Image.py and imports that. When you do PIL.Image you are actually doing an attribute lookup on the PIL module (which is just an empty stub unless you explicitly import stuff).
In fact, importing a module usually doesn't import submodules. os.path is a famous exception, since the os module is magic.
More info:
The Image Module
If you, like me, found the accepted answer a bit befuddling because you could swear you've been able to use
import PIL
PIL.Image
sometimes before, a potential reason for this is if any other code in your Python session has run from PIL import Image or import PIL.Image, even if it's in a completely different scope, you will be able to access PIL.Image.
In particular, matplotlib does so when it's imported. So if you run
import matplotlib
import PIL
PIL.Image
it works. Thanks, Python.
Don't trust anyone. Don't trust Python. Use import PIL.Image.
You can do:
try:
import Image
except ImportError:
from PIL import Image
it's better to use pillow instead PIL.
The solution is
instead of using this form
import PIL
PIL.Image
use this form
from PIL import Image
Image
in the Linux system both forms work fine
but in windows, there is a problem

Categories

Resources