pillow

Python 学习总结(三):巧用各类模块,方便维护

五迷三道 提交于 2019-12-13 17:06:36
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 这节的内容主要讲下模块的使用,很好很强大,有木有。在开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护。为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少,很多编程语言都采用这种组织代码的方式。下面就来认识一下关于模块: (1)模块的概念 在Python中,一个.py文件就称之为一个模块(Module)。使用模块可以避免函数名和变量名冲突。相同名字的函数和变量完全可以分别存在不同的模块中,因此,我们自己在编写模块时,不必考虑名字会与其他模块冲突。但是也要注意,尽量不要与内置函数名字冲突。 (2)模块分类 模块大体可以分为三种: 内置模块:如 sys, os, subprocess, time, json 等等,无需安装配置,直接导入使用 自定义模块:注意命名,不要和python自带的模块名称冲突,通过导入使用 开源模块:公开的第三方模块,如Windows下通过pip install + 模块名安装后导入使用 (3)模块的使用 前提是Python安装成功,PATH环境变量完整,在第一节已经说过了,可以回顾下。当然了,使用模块的格式很简单,导入就行了: import语句,导入整个模块: import module1,module2,...

Count total number of pages in .TIF file in Python

情到浓时终转凉″ 提交于 2019-12-13 15:27:59
问题 I'm trying to get Python to read exactly how many pages are in a .TIF and I've modified some code from some help I got yesterday. I've gotten Python to read the .TIF file, and output the pages, however it only reads the first .TIF file it can find. I need it to go through all the .TIF files in the same location. I was wondering how can I make it so that once it is done counting, it will continue to the next file until it is completely done. Here is what I have so far import os from PIL import

undefined symbol: PyUnicodeUCS4_AsLatin1String when installing Pillow for local Python

我的梦境 提交于 2019-12-13 15:15:01
问题 I used pip to install Pillow. It indicated successful installation of Pillow. But when in Python (v2.7.8), I entered from PIL import Image , I got this error: ImportError: /home/local/python2/lib/python2.7/site-packages/PIL/PIL/_imaging.so: undefined symbol: PyUnicodeUCS4_AsLatin1String The problem is that I have a local python v2.7.8 install which is for UCS2 with maxunicode : 65535. But the PIL library was built and installed by the system default Python 2.7.6 version, which is UCS4. I

ImportError: Could not import the Python Imaging Library (PIL) required to load image files

北慕城南 提交于 2019-12-13 14:16:53
问题 I am trying to run the average.py program in the facemorpher 1.0.1 python package. I have created a virtual environment that has openCV installed with homebrew, python 2.7 installed in homebrew, and executable frameworkpython that makes a framework build of python inside the virtual environment cv . running the average program currently gives me this output. (cv) Francess-MacBook-Pro-2:face_morpher Megan$ frameworkpython facemorpher/averager.py --images=IMFDB_final/Ali/HelloBrother/images -

Pyinstaller troubles with Pillow

不羁岁月 提交于 2019-12-13 13:33:36
问题 I'm trying to use pyinstaller, on OSX Mavericks, with one a Python script. Pyinstaller compiles and packs along until it finds an error with the Pillow library. ImportError: dlopen(/Users/Rodolphe/.python-eggs/Pillow-2.2.1-py2.7-macosx-10.9-intel.egg tmp/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.8.dylib Referenced from: /Users/Rodolphe/.python-eggs/Pillow-2.2.1-py2.7-macosx-10.9-intel.egg-tmp/PIL/_imaging.so Reason: Incompatible library version: _imaging.so requires

Different image data from the same source with Pillow

会有一股神秘感。 提交于 2019-12-13 07:13:33
问题 I am currently moving a script which creates local sensitive hashes from images from a windows host to a debian one. My problem is Pillow returns different image data from the same source image on both platforms. I only observed this behavior for jpegs. Test case: from PIL import Image import md5 import urllib2 from cStringIO import StringIO urls = ("https://i.imgur.com/Mx6NQwM.jpg","https://i.imgur.com/MN1TKu5.png") print("VERSION %s" % Image.VERSION) for url in urls: response = urllib2

AttributeError: 'str' object has no attribute 'tostring'

给你一囗甜甜゛ 提交于 2019-12-13 05:05:28
问题 Trying to convert image to string.... import requests image = requests.get(image_url).content image.tostring() I get the error: AttributeError: 'str' object has no attribute 'tostring' How do I turn this into something that Python understands as an image which I can then call tostring() on? 回答1: The .content attribute of a response is already a string . Python string objects do not have a tostring() method. Pillow / PIL in not coming into play here; the requests library does not return a

How to install pillow on pypy

久未见 提交于 2019-12-13 04:38:11
问题 How do I install pillow on Windows pypy with png support. I tried pypy -m pip install --use-wheel pillow This does not find a wheel file (for pypy), so it creates pillow, but does not include png support because it does not find zlib. I don't want to modify the setup.py, because I want to do this on multiple machines. 回答1: How about installing manually zlib.dll in system32? http://www.winimage.com/zLibDll/index.html 来源: https://stackoverflow.com/questions/20737151/how-to-install-pillow-on

How to display a picture from mysql database using python?

谁说胖子不能爱 提交于 2019-12-13 02:48:41
问题 I want to display a picture I already saved on the table img, but it gives me an error cannot identify image file When it try to open the file_like . Cursor and connection use the connection and password to mysql database. With the following code I wanted to display the picture. What's wrong with it, or is there even a better/easier way? sql1='select * from img' connection.commit() cursor.execute(sql1) data2=cursor.fetchall() file_like=cStringIO.StringIO(data2[0][0]) img1=PIL.Image.open(file

Django. How to save a ContentFile edited with Pillow

≡放荡痞女 提交于 2019-12-12 21:18:52
问题 I'm trying to save an image I download with requests and then edit with Pillow to ImageField in a model. But the object is being created without the image. This is what I have: settings.py MEDIA_ROOT = BASE_DIR + "/media/" MEDIA_URL = MEDIA_ROOT + "/magicpy_imgs/" models.py def create_path(instance, filename): path = "/".join([instance.group, instance.name]) return path class CMagicPy(models.Model): image = models.ImageField(upload_to=create_path) .... # Custom save method def save(self,