I've installed pillow and can't import it into the python shell - python-imaging-library

I've looked over 30 different pages and couldn't find the answer I needed. I'm using a windows 10 and I'm using python 3.9.0. So I installed Pillow 8.1.0 like this:
python3 -m pip install --upgrade Pillow
Then tried to import pillow into the shell using:
import PIL
import Pillow
import pillow
from Pillow import Image
from PIL import Image
from PIL import *
from Pillow import *
but I got the ModuleNotFoundError every time.
Do you have another way to put pillow into the python shell?
Thanks for the answer in advance😄.

If you're still having trouble, try this:
in your python terminal run:
import sys
print(f'"{sys.executable}" -m pip install pillow')
print(f'"{sys.executable}" -m pip install requests')
then, with the printouts you get, run your windows command prompt as an admin (right click -> run as admin) then paste the 2 commands you get back. restart python and you SHOULD be good to go.

With python 3.9 and above using Pillow 8.1.0, use
from pil import Image.

Related

How can i use PIL in python?

I have successfully installed Pillow:
chris#MBPvonChristoph sources % python3 -m pip install --upgrade Pillow
Collecting Pillow
Using cached Pillow-9.0.1-1-cp310-cp310-macosx_11_0_arm64.whl (2.7 MB)
Installing collected packages: Pillow
Successfully installed Pillow-9.0.1
but when i try to use it in pycharm got:
Traceback (most recent call last):
File "/Users/chris/PycharmProjects/pythonProject2/main.py", line 1, in
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
or using in Blender i got:
ModuleNotFoundError: No module named 'PIL'
I am not a python lib installing pro...so obviously i made something wrong. But how do i fix that?
Maybe i have to say i am working on a M1 Macbook
looks like you may need to repoint your pycharm to your installed python interpreter.
go to command line and find out python interpreter path. On windows you can where python in your command line an it will give you where your python and packages are installed.. You could also activate python directly in command line and find paths from there. For example, open command line then;
python
press enter = activates python
within then you can do:
import sys
for x in sys.path: x
In pycharm make sure you point to path discovered from step 1 and select that to be your python interpreter within pycharm --- check out examples here https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add-existing-interpreter
Should work. Not sure about all the steps you took, but if you installed python with pycharm on top of your regular installation of python i would recommend :
finding all the paths from step 1
deleting python using system
checking if folders found from paths step still exist
if they do, delete those as well
start over just with one python installation
repoint to that in pycharm
first
pip uninstall PIL
after uninstall
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
or
brew install Pillow

Using Pillow for python 3.7 Mac OS?

I have Pillow installed successfully on my Mac, but when I type in
from PIL import Image
I get an error: "Unable to import 'PIL'
I'm using VSCode by the way. Anyone know how to fix this? I've looked through almost every stack overflow post, but can't seem to figure it out. I tried uninstalling and reinstalling, deleting PIL, etc. I have Pillow-7.1.2 by the way.
If you installed Pillow with:
pip install pillow
then you can find where it is installed with:
pip show pillow
Sample Output
Name: Pillow
Version: 7.1.2
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark#python-pillow.org
License: HPND
Location: /usr/local/lib/python3.7/site-packages <--- HERE
Of course, if you installed with:
pip3 install pillow
you will need:
pip3 show pillow
Now go to your Python interpreter and check where it is looking for packages and you will surely work out the problem:
python3 -c "import sys; print(sys.path)" | tr , '\n'
Samnple output
[
'/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python36.zip'
'/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6'
'/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload'
'/usr/local/lib/python3.6/site-packages'
'/usr/local/Cellar/numpy/1.13.3/libexec/nose/lib/python3.6/site-packages']
Of course, if you start Python with python rather than python3, you will need:
python -c "import sys; print(sys.path)" | tr , '\n'
Finally, go to your Terminal and find out what your shell actually runs when you enter python by running:
type python # or "type python3" if you normally enter "python3"
Now go in your IDE and see which Python that runs:
import sys
print(sys.executable)

How to execute the right Python to import the installed tensorflow.transform package?

The version of my Python is 2.7.13.
I run the following in Jupyter Notebook.
Firstly, I installed the packages
%%bash
pip uninstall -y google-cloud-dataflow
pip install --upgrade --force tensorflow_transform==0.15.0 apache-beam[gcp]
Then,
%%bash
pip freeze | grep -e 'flow\|beam'
I can see that the package tensorflow-transform is installed.
apache-beam==2.19.0
tensorflow==2.1.0
tensorflow-datasets==1.2.0
tensorflow-estimator==2.1.0
tensorflow-hub==0.6.0
tensorflow-io==0.8.1
tensorflow-metadata==0.15.2
tensorflow-probability==0.8.0
tensorflow-serving-api==2.1.0
tensorflow-transform==0.15.0
However when I tried to import it, there are warning and error.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/__init__.py:12: The name tf.estimator.inputs is deprecated. Please use tf.compat.v1.estimator.inputs instead.
ImportErrorTraceback (most recent call last)
<ipython-input-3-26a4792d0a76> in <module>()
1 import tensorflow as tf
----> 2 import tensorflow_transform as tft
3 import shutil
4 print(tf.__version__)
ImportError: No module named tensorflow_transform
After some investigation, I think I have some ideas of the problem.
I run this:
%%bash
pip show tensorflow_transform| grep Location
This is the output
Location: /home/jupyter/.local/lib/python3.5/site-packages
I tried to modify the $PATH by adding /home/jupyter/.local/lib/python3.5/site-packages to the beginning of $PATH. However, I still failed to import tensorflow_transform.
Based on the above and the following information, I think, when I ran the import command, it executes Python 2.7, not Python 3.5
import sys
print('\n'.join(sys.path))
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages/IPython/extensions
/home/jupyter/.ipython
Also,
import sys
sys.executable
'/usr/bin/python2'
I think the problem is tensorflow_transform package was installed in /home/jupyter/.local/lib/python3.5/site-packages. But when I run "Import", it goes to /usr/local/lib/python2.7/dist-packages to search for the package, rather than /home/jupyter/.local/lib/python3.5/site-packages, so even updating $PATH does not help. Am I right?
I tried to upgrade my python, but
%%bash
pip install upgrade python
Defaulting to user installation because normal site-packages is not writeable
Then, I added --user. It seems that the python is not really upgraded.
%%bash
pip install --user upgrade python
%%bash
python -V
Python 2.7.13
Any solution?
It seems to me that your jupyter notebook is not using the right python environment.
Perhaps, you installed the package under version 3.5,
but the Notebook uses the other one, thus it cannot find the library
You can pick the other interpreter by clicking on: Python(your version) - bottom left.
VS-Code - Select Python Environment 1
However you can do this also via:
CNTRL+SHIFT+P > Select Python Interpreter to start Jupyter Server
If that does not work make sure that the package you are trying to import is installed under the correct python environment.
If not open up a terminal, activate the environment and install it using:
pip install packagename
For example i did the same thing here: (Note: I'm using Anaconda)
installing tensorflow_transform
After a installation, you can import it in your code directly like this:
importing tensorflow_transform

Uninstalled Pil/Pillow but can still import from it?

I've run the following commands on the virtual enviroment.
pip uninstall pillow
Skipping pillow as it is not installed.
pip uninstall pil
Skipping pil as it is not installed.
However when I do this in the console:
import PIL print PIL.PILLOW_VERSION
I get this: 5.3.0
import PIL print PIL.VERSION
I get this: 1.1.7
When I try to reinstall PIL in case there was an issue when installing it, I get this:
Could not find a version that satisfies the requirement pil (from versions: )
No matching distribution found for pil
When I try to uninstall from the python interpreter directly:
Cannot uninstall 'PIL'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
I'm trying to completely remove PIL and PILLOW on a windows machine.
I would recommend going into the Python interpreter and writing
>>> import PIL
>>> PIL
You should then see a path to the Pillow module, which you can manually remove.

Install BeautifulSoup, mrjob, pattern, and seaborn on python 2.7 on Jupyter

I am learning how to use the new Jupyter. I want to install packages:BeautifulSoup, mrjob, pattern, and seaborn on python 2.7. I first tried to do so by running pip install BeautifulSoup mrjob pattern seaborn That all returns: SyntaxError: invalid syntax
I also tried from bs4 import BeautifulSoup, it did work for Beautifulsoup. But I still don't know how to install other packages.
Wondering anyone know why there was syntax error for using pip install? Is that because I haven't installed pip on python 2.7?
I was also able to install these packages from iphython notebook window by running
import pip
def install(package):
pip.main(['install', package])
install('BeautifulSoup4')
Have you tried installing one package at a time. This helps you find which installation command not working.
You can find Julia packages here.
The problem was I was running pip from inside Jupyter. However, Jupyter is a command line program. Thanks to Mwaskom, the solution is run it from a terminal using:
pip install BeautifulSoup mrjob pattern seaborn
You could try:
!pip install BeautifulSoup mrjob pattern seaborn