Is there a way to have Python pull up a picture (that is stored locally) for a user to view and then have that user input information about that picture, which information is then stored locally?
I found some information about the Image library, but I can't get the Image library to work. When I use the following code, I get an error:
import Image
ImportError: No module named Image
from PIL import Image
ImportError: No module named PIL
I tried to install pillow using
pip install pillow
I'm not sure if it installed correctly. Any one else have this problem? I'm using Python 2.7. I know that I can eventually use the following code to view the picture:
Image.open('example.jpg').show()
Related
I have installed the PIL library using pip like this:
pip install Pillow
and it's working fine also showing library path in interrupter PyCharm Options.
But Autocomplete is not working, I tried to turn off the Power Save Mode and added custom virtual env, but it's still not working.
Any idea why it does not work?
So it's now showing sub methods :
from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
PyCharm doesn't know the type of im as the library has no type hints for Image.open(). So I decided to set local type hint like this:
your_image = Image.open(path_to_image) # type: Image.Image
your_image.now_shows_list = True
For complete reference look at JetBrains type hints documentation.
The problem is that:
PIL.Image is a module (normally lowercase)
The module contains a function called open()
open() returns a Type of PIL.Image.Image
PyCharm does not realise it returns this type unless you tell it (I don't why).
https://pillow.readthedocs.io/en/3.0.x/handbook/tutorial.html#using-the-image-class
To avoid clashes with my project on the name "Image", as well as to stay Pep8 and adhere to google's style guide, I opted for:
from PIL import Image as PilImage
my_image: PilImage.Image = PilImage.open("my_image.png")
my_image.show()
Running on python 3.8.2
I am novice in python and Simple_ITK both to process .mha 3D image files. I have two problems:
When ever I install ITK, I always get an error as shown below:
and somehow I install ITK It doesn't work at all having no connectivity with python. And I also tried python-insighttoolkit3 package then it shows and error of
" Can't down load Python 2.8:i386" in Ubuntu software Center. I have tried various methods to install Insight Tool Kit in Ubuntu whatever I found but most of the time I get the same error as shown in picture above.
So can anybody guide me how to install and build ITK so that no error like no module named itk found.
Now another problem is I have a .py file and it has a class in which I have to fed input externally otherwise it will consider as None. SO I tried to call the file as
import /path/to/file/xxx.py
but it gives an Syntax error: invalid syntax
so how to call class from a python file from python Console .
Now, I'm using Ubuntu 15.02. For any missing details please ask.
Thanks.
1- For what I see in the image, I see that you are trying to install ITK instead of SimpleITK. For SimpleITK it is very simple using a linux package installer, like pip or easy-install. in this link you have the instructions to install it correctly. Remember to execute the instructions as super user. Maybe it is the reason of your error ( I can't see the instruction you are writing in the console ).
2- I recommend you to read the Python tutorial for modules The fastest way is to be located first on the directory of your .py file. The sequence would be:
cd /path
import module.py
I tried to use Python's Image Module on my Mac (new to mac)and I had trouble setting it up. I have Yosemite and some of the posts that I found online didn't work. I ended up installing Homebrew and I finally got PIL on my computer. However, instead of using import image (which I saw people doing it online), I have to use from PIL import image. Is there key difference between import Image and from PIL import Image. It's the first time that I actually use Image module.
One more question, do I actually need to install third party tools like Homebrew and Macports to set up my environment?
If you are using PIL, you might be able to use import Image.
If you are using Pillow, you must use from PIL import Image.
This is by design.
1-Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
2-Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead. so be careful with it
3-Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.
In python, modules are represented by *.py files. These files can be imported using import module. That statement will first search for a build-in module, if it fails to find one it will search in a given list of directories (PYTHONPATH).
When you imported your module, you can then access names (aka functions or classes) via module.name.
However, when using from module import myFunc you can reference that function directly without using the modulename. The same goes for from module import *.
Now, to the PIL:
Image is a name (here class) in the PIL module. As, import Image searches for modules called Image. It can't find one, because Image is part of the PIL module.
You can also look at the documentation here: Modules in Python
I hope this helped you understanding modules better.
for my facebook app, I am trying to generate image from the data. So, I need to put the text and some images on another background image . I thought of using PIL, but it had lot of dependencies which are making me mad. Also, at the end I have to do all these installations on heroku also . So, anyway simple way to add text and image to another image in python#Django ?
Some of the problems using pil : when using font feature, getting this error : The _imagingft C module is not installed
I installed pillow also .
You will need some form of an image processing library. Even some components of Django, like ImageField, need PIL.
If you are having problems building PIL, there is a fork called Pillow, which supposedly aims to package it up better to make installation easier.
easy_install pil results in an error:
Searching for pil
Reading http://pypi.python.org/simple/pil/
Reading http://www.pythonware.com/products/pil
Reading http://effbot.org/zone/pil-changes-115.htm
Reading http://effbot.org/downloads/#Imaging
No local packages or download links found for pil
error: Could not find suitable distribution for Requirement.parse(‘pil’)
Any ideas?
--
UPDATE:
Hm, asking it to find-links on the Python Ware site seems to be working:
easy_install -f http://www.pythonware.com/products/pil/ Imaging
Got a heap of warnings along the way though. I’ll see how it turns out.
--
UPDATE: I can import it in Python using import Image, but when I tell Django to syncdb I still get the following error:
Error: One or more models did not validate:
core.userprofile: “avatar”: To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .
I'm using an ImageField in one of my models.
Of course PIL is on PyPi! Specifically, it's right here.
easy_install is case-sensitive. The package is under PIL.
workaround is in easy_install PIL egg directory create link to this directory in name "PIL"
import Image
Django tries to import PIL directly:
from PIL import Image
You should check presence of PIL directory in your site-packages
from http://code.djangoproject.com/ticket/6054
It seems that there is something wrong with easy_install which installs PIL in the root namespace, installing from sources fixes this, strange.