Python Can't Find Modules - python

I'm running a python script which resizes and converts images to JPG and an RGB. This script worked perfectly until I upgraded my computers HD and moved everything over from my Time Machine backup. Now when I try to run the script it can't find any modules. Specifically the Image module (I use Pillow).
Traceback (most recent call last):
File "processImgs.py", line 1, in <module>
import os, sys, argparse, shutil, imgFunctions
File "/web/script/python/img_processing/imgFunctions.py", line 1, in <module>
import os, sys, Image, shutil, re
ImportError: No module named Image
I am using Homebrew to manage my modules, and "brew list" outputs the following:
freetype graphicsmagick libpng libtool little-cms2 openssl pkg-config readline webp
gdbm jpeg libtiff little-cms openjpeg pillow python sqlite
If i run "pip list" I get:
Pillow (2.3.0)
pip (1.5.4)
setuptools (2.2)
wsgiref (0.1.2)
If i run "help(modules)" in python, the Image module isn't listed.

Could be your python path isn't set up correctly after the move.
see here for the homebrew/python docs page and it seems that a reinstall of homebrew may fix it.

Related

How can I import in Python simple coding error

I have started any coding for example: from PIL import Image, I encountered such an error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
I will be pleased that guide me.
In shell, run:
pip install Pillow
PIL is deprecated - Pillow is its replacement
This means that the package is not installed. To install it, you will need pip, a package installer for python.
Here is the Pillow package official website, which you can use to understand how to install the package: https://pillow.readthedocs.io/en/stable/installation.html. All the commands on the site are typed into Terminal on MacOS and Linux and the cmd on Windows.

How can Pillow and MATLAB Runtime be used together on macOS?

In order to use the MATLAB runtime on macOS, the DYLD_LIBRARY_PATH must be updated to point to the MATLAB Runtime.
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Applications/MATLAB_R2017b.app/runtime/maci64:/Applications/MATLAB_R2017b.app/sys/os/maci64:/Applications/MATLAB_R2017b.app/bin/maci64
Then, to use Pillow, it must be installed:
$ pip3 install Pillow
When running the following code:
from PIL import Image, ImageTk
print('Hello World')
The following error is shown:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from PIL import Image, ImageTk
File "/Users/user/venv/py-test/lib/python3.6/site-packages/PIL/Image.py", line 58, in <module>
from . import _imaging as core
ImportError: dlopen(/Users/user/venv/py-test/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-darwin.so, 2): Library not loaded: #loader_path/.dylibs/libtiff.5.dylib
Referenced from: /Users/user/venv/py-test/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-darwin.so
Reason: Incompatible library version: _imaging.cpython-36m-darwin.so requires version 9.0.0 or later, but libtiff.5.dylib provides version 6.0.0
If run without the first export command, Pillow works fine, but I can't find out a way to get both to work at once. The MATLAB Runtime is exporting an older version of libtiff that Pillow (even though it's install via a binary wheel) is loading:
/Applications/MATLAB_R2017b.app/bin/maci64/libtiff.5.dylib
System configuration
macOS 10.11.6
Python 3.6.4 installed via Homebrew
Pillow 5.0.0
MATLAB Runtime 2017b

DLL load failed, DLLs not in right location

I have pygame 1.9.2 for Python 3.2+. However, when I try to start up Python with pygame, I receive: "ImportError: DLL load failed: The specified module could not be found." I found the files it needs, but where should I put them?
This is my full error traceback:
Traceback (most recent call last):
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\hg.py", line 1, in <module>
import pygame
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
Most pygame errors in windows 10 are caused by having an out-of-date pygame by installing the compiled .exe version while not installing it from the official source, since their version is different from the PyPi index.
You will have to download the corresponding file suitable for your system from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Then do
pip install c:/path/to/the/wheelfile.whl
You must have installed pygame incorrectly or something went wrong during installation. I would uninstall pygame and reinstall it with the pip command.
Go to the search bar at the bottom left of your desktop (on your taskbar) and enter cmd. This will open the command line interface (CLI). Then go to here: https://pip.pypa.io/en/stable/installing/ and install the file get-pip.py. Once this has been completed, go to the cmd you opened earlier and enter python get-pip.py. This should install pip, setuptools and wheel.
After this, use the command below to install pygame:
pip install pygame
Then try a simple test to see if it works:
import pygame
print(pygame)

Challenge installing psd-tools on fresh Mac

I've been using PSD-TOOLS to great effect on a 13" notebook for half a year now (Python 2.7.3). Just tried to do a fresh install on a Mac running 10.8.4.
I ran through the python setup at http://docs.python-guide.org/en/latest/starting/install/osx/ (Python version
Installed Pil using:
sudo pip install pil
All my Pil scripts work fine.
pip list
shows PIL (1.1.7) installed fine.
Then tried to install psd-tools using:
sudo pip install psd-tools
Appears to install fine but when I run my PSD scripts, get the following:
File "/Library/Python/2.7/site-packages/psd_tools/user_api/psd_image.py", line 91, in as_PIL
return self._psd._layer_as_PIL(self._index)
File "/Library/Python/2.7/site-packages/psd_tools/user_api/psd_image.py", line 243, in _layer_as_PIL
return pil_support.extract_layer_image(self.decoded_data, index)
File "/Library/Python/2.7/site-packages/psd_tools/user_api/pil_support.py", line 32, in extract_layer_image
decoded_data.header.depth, get_icc_profile(decoded_data))
File "/Library/Python/2.7/site-packages/psd_tools/user_api/pil_support.py", line 68, in _channels_data_to_PIL
raise Exception("This module requires PIL (or Pillow) installed.")
Exception: This module requires PIL (or Pillow) installed.
Anybody run into this issue?
I ran into this issue on OSX 10.9 with Python 2.7.5. (In a virtualenv)
I ended up going over https://pypi.python.org/pypi/Pillow/2.2.1 and installing some optional prerequisites for Pillow.
#I already had libjpeg but this is the line in their doc.
brew install libtiff libjpeg webp littlecms
#Then re-installed Pillow
pip install --force-reinstall --upgrade pillow
The result was the following features enabled
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- TIFF G3/G4 (experimental) support available
*** FREETYPE2 support not available
--- LITTLECMS support available
--- WEBP support available
--- WEBPMUX support available
And my small python test ran
from PIL import Image
from psd_tools import PSDImage
psd = PSDImage.load('test_data/1.psd')
merged_image = psd.as_PIL()
Not sure which of those requirements was responsible so if you are not interested in installing extra libraries you may have to do 1 at a time or dig into the source.

No module named Image

Sorry for my grammar, I don't speak English.
After I set filebrowser, tinymce, and grappelli, I get this error: No module named Image
try:
from PIL import Image
except ImportError:
import Image
I set it to PIL but it didn't solve the problem.
my platform windows
If i want: pip install PIL
`c:\Users\Kim\BitNami DjangoStack projects\homex8>pip install PIL
Downloading/unpacking PIL
Running setup.py egg_info for package PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
building '_imaging' extension
error: Unable to find vcvarsall.bat`
I do not understand what that means
Solved problem.
reinstall PIL with easy_install, and more movements, here are the details.
You are missing PIL (Python Image Library and Imaging package). To install PIL I used
pip install pillow
For my machine running Mac OSX 10.6.8, I downloaded Imaging package and installed it from source.
http://effbot.org/downloads/Imaging-1.1.6.tar.gz and cd into Download directory. Then run these:
$ gunzip Imaging-1.1.6.tar.gz
$ tar xvf Imaging-1.1.6.tar
$ cd Imaging-1.1.6
$ python setup.py install
Or if you have PIP installed in your Mac
pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz
then you can use:
from PIL import Image
in your python code.
Did you setup PIL module? Link
You can try to reinstall it on your computer.
It is changed to : from PIL.Image import core as image
for new versions.
You can this query:
pip install image
I had pillow installed, and still, I got the error that you mentioned. But after I executed the above command, the error vanished. And My program worked perfectly.
Problem:
~$ simple-image-reducer
Traceback (most recent call last):
File "/usr/bin/simple-image-reducer", line 28, in <module>
import Image
**ImportError: No module named Image**
Reason:
Image != image
Solution:
1) make sure it is available
python -m pip install Image
2) where is it available?
sudo find ~ -name image -type d
-->> directory /home/MyHomeDir/.local/lib/python2.7/site-packages/image
->> OK
3) make simple-image-reducer understand via link:
ln -s ~/.local/lib/python2.7/site-packages/image
~/.local/lib/python2.7/site-packages/Image
4)
invoke simple-image-reducer again.
Works:-)
If you are trying to just show the image on your notebook, below simply does the job
from IPython.display import Image
Image(url= "Link to the image ending with file format such as, .jpg or .png")

Categories

Resources