I'm new to python and am not really sure how importing libraries works, but I understand that you are supposed to use "from PIL import Image" in order to import the Image module (is it even called a module???) and then use Image.open("filename") in order to open the Image, but I got a "No module named 'PIL'" error when I tried to import it from PIL. I then just did "import Image" which didn't raise any error flags but I still can't use Image.open without getting an "Undefined variable from import" error.
Any help is appreciated!
You need to install Pillow in order to use PIL
In your command line, type:
$ pip install Pillow
After that, you can use from PIL import Image
In Python, you may sometimes need to install a library before using it. To install a library goto command prompt and type this command:
pip3 install Pillow
you will see some stuff install and if you get no error message, you are good to go. Now rerun your program.
Related
Basically, i'm trying to use the turtle module at home as I have been using it in school and it's quite fun to use. However, when I try to import it and run the code, it says that there is an error in line 1 of the code and says that no module named pygame was found. I didn't write pygame, I specifically wrote
from turtle import *
which at school works perfectly fine. Both my computer and the school computers use Python 3.6 but the turtle module will just not work at home. Any ideas why this might be happening? If it helps, I've tried to install pygame in the past but it wouldn't work so I stopped trying to install it, and just now I tried deleting and uninstalling pygame but it still shows up with the error. Thanks for taking your time to read my question.
The error that comes up is as follows:
Traceback (most recent call last):
File "C:/Users/homeuser/AppData/Local/Programs/Python/Python36-32/jsjs.py", line 1, in <module>
from turtle import *
File "C:/Users/homeuser/AppData/Local/Programs/Python/Python36-32\turtle.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
>>>
Also, pip install pygame comes up with an error saying invalid syntax
First, you need to download the version of pygame suitable for your version of python. Here's a link to their download page: https://pypi.python.org/pypi/Pygame/1.9.3
Next, open the command prompt. This technique works provided that you have pip installed and you have the required environmental variables.
Now, type in the following into the command prompt: 'python -m pip install "Path/To/Downloaded/File.py"'
Here's a real-life example: 'python -m pip install "C:/Users/danie/Downloads/pygame-1.9.3-cp36-cp36m-win_amd64.whl"'
If you have any errors, it would most likely because:
- (A) You don't have pip installed properly.
- (B) You gave an invalid directory branch.
- (C) You spelled something in the command wrong.
- (D) You forgot to download the Pygame module.
I hope this helps.
Pygame should be a dependency of turtle. Try to download pygame with pip.
More information about the installation:
https://www.pygame.org/wiki/GettingStarted
You've been working inside a Python standard library directory, placing your own files there and clobbering Python's insides. The error you're seeing is because you've edited or replaced the turtle.py from the standard library. At this point, there's no telling how much damage has occurred, and manually fixing things isn't going to be practical.
Uninstall and reinstall Python to restore things to normal, and stop putting your own work in that directory.
Seeing the error code you've posted, it seems that some files placed in the python directory have been messed with or there must have been some changes. Nevertheless, You can try doing an uninstall and then doing a clean install of python.
Then proceed to download pygame by:
pip install pygame
and then turtle module. You may have to look up for the Tkinter module too.
when I run a programme containing:-
from pythonds.basic.stack import Stack
it says:-
ImportError: No module named pythonds.basic.stack
Please help me out.
pip install pythonds.
And then from pythonds.basic.stack import Stack. Note that it's Stack, not stack.
If you don't have the Python PATH variable configured, then type this into your command prompt:
C:\Python34\Scripts\pip install LIBRARY NAME
This path is only and example. change it wherever you have Python in your pc.
I'm getting an error while using PyCharm which doesn't allow me to import the pillow module even though I have it installed as a package in the project interpreter. Any help is greatly appreciated!
http://imgur.com/a/DfjC3
While the name of the package is pillow, it is a replacement for PIL and uses the PIL for the name of the base module
the usual way to use pillow is
from PIL import Image
im = Image.open("filename")
See the tutorial, and the documentation
You try to run code with default Python interpreter (/Library/Frameworks/Python.framework/Versions/3.2/bin/python3). You need to configure PyCharm to run Your code with anaconda (~/anaconda/bin/python)
And now (Like #JamesK say) read Pillow tutorial and documentation:
import PIL not import Pillow
For anybody still having trouble with this, I did the following which solved my problem.
Open up your Project Interpreter (⌘ + , on Mac).
At the bottom of this page you'll see the + symbol to the left of the anaconda logo. This will create a pop-up that allows you to search for available packages.
In this new window, search for 'Pillow'.
Click and Install Package.
You should now be able to use "from PIL import Image" or "import Pillow as pil" etc.
After running this command on your terminal
pip install pillow
and you are sure it was installed, but still having same problem of PIL module not found.
Go to your IDE and make sure existing interpreter is set to python interpreter and not anaconda
I am trying to download the Pygraphics module using Python 2.7.6 and have been heretofore unsuccessful. Below I detail the steps I have taken so far. Any help with this would be most appreciated.
First, I tried the typical install using pip
sudo pip install Pygraphics
When I try to import the module, I receive an error saying ImportError: No module named Pygraphics.
To test whether the module was installed I ran the following code: print sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()]) which showed me all of my installed distributions.
This code returned the following list of all the distributions and clearly showed that Pygraphics is installed:
['altgraph==0.10.2', 'bdist-mpkg==0.5.0', 'bonjour-py==0.3', 'brewer2mpl==1.4', 'certifi==14.05.14', 'datetime==4.0.1', 'flask==0.10.1', 'ggplot==0.6.5', 'ipython==2.0.0-dev', 'itsdangerous==0.24', 'jdcal==1.0', 'jinja2==2.7.3', 'macholib==1.5.1', 'markupsafe==0.23', 'matplotlib==1.4.x', 'mock==1.0.1', 'modulegraph==0.10.4', 'nose==1.3.4', 'numpy==1.9.0.dev-297f54b', 'openpyxl==2.1.2', 'pandas==0.14.1', 'pandasql==0.6.1', 'patsy==0.3.0', 'pika==0.9.14', 'py2app==0.7.3', 'pygments==1.6', 'pygraphics==2.1']
After this, I tried using the GUI installer located on the following Pygrahpics install website. While going through the installer, I received an error message saying "PyGraphics requires System Python 2.7 to install" despite the fact that I have downloaded Python 2.7.6.
At this point I don't know what to do and was hoping someone who may have had a similar issue might be able to help me out.
Thank you for your time.
It looks like you've successfully install PyGraphics. Now import picture :)
I'm getting an error about a module and have searched for a solution for some time now and have come up empty handed. I'm coding in python and working in eclipse pydev. At the top of my code I typed.
import Image
I get a error that states ImportError: No module named Image
Here is just some screenshots of the Python Interpreter System Pythonpath
http://imageshack.us/a/img5/614/92989360.png
http://imageshack.us/f/545/79985417.png/
You need to install the Python Image Libray:
PIL
You can install it using pip via:
pip install PIL