我试过谷歌搜索和查找其他人的问题.但是,我仍然找不到在mac os x 10.7.2 Lion上安装PIL(for python 2.6或2.7)的清晰/简单配方.
我想在图像中添加俄语文本.我在Windows机器上使用PIL 1.1.7和Python 2.7.由于PIL编译时没有libfreetype库,我在开发服务器上使用以下代码:
font_text = ImageFont.load('helvR24.pil')
draw.text((0, 0), '????? ?? ???????', font=font_text)
Run Code Online (Sandbox Code Playgroud)
(helvR24.pil摘自http://effbot.org/media/downloads/pilfonts.zip)
在生产环境中,我执行以下操作:
font_text = ImageFont.truetype('HelveticaRegular.ttf', 24, encoding="utf-8")
draw.text((0, 0), '????? ?? ???????', font=font_text)
Run Code Online (Sandbox Code Playgroud)
(试图使用unic,cp-1251而不是utf-8)
在这两种情况下,它都不显示俄语字符(而是显示"正方形"或虚拟字符).我认为它不适用于开发环境,因为大多数可能helvR24.pil不包含俄语字符(不知道如何检查它).但HelveticaRegular.ttf肯定有.我还检查过我的.py文件有геа-8编码.即使使用默认字体,它也不会显示俄语字符:
draw.text((0, 0), '????? ?? ???????', font=ImageFont.load_default())
Run Code Online (Sandbox Code Playgroud)
我还应该尝试/验证什么?我通过/sf/answers/1311065871/查看 - 它没有帮助.
我正在使用Django的Python Web开发学习一个小Django .一切顺利,直到我尝试构建需要PIL(Python成像库)的照片应用程序.当我尝试通过管理界面添加图像时,我收到下面粘贴的错误消息.
我正在运行Windows 7,Python 2.7,Django 1.3b1和XAMPP 1.7.3并成功安装了wsgi模块(至少我是这么认为的,因为我的其余Django实验工作正常).
按照PIL站点的故障排除指南,我尝试在Python提示符下导入PIL模块:
>>>import _imaging
>>>import Image
Run Code Online (Sandbox Code Playgroud)
两者都工作正常,没有显示错误.但是,尝试运行使用PIL的Django管理应用程序会导致:
ImportError位于/ admin/items/photo/add /未安装_imaging C模块请求方法:POST请求URL: http:// localhost:8888/photos/admin/items/photo/add / Django版本:1.3 beta 1 SVN -15679异常类型:ImportError异常值:
未安装_imaging C模块异常位置:getattr中的 C:\ Python27\lib\site-packages\PIL\Image.py ,第37行Python可执行文件:C:\ xampp\apache\bin\httpd.exe Python版本:2.7.0 Python路径:
['C:\ Python27\lib\site-packages\ipython-0.10-py2.7.egg','C:\ Python27\lib\site-packages\sqlalchemy-0.6.4-py2.7.egg','C:\ Python27\lib\site-packages\openglcontext_full-2.1.0a7-py2.7.egg','C:\ Python27\lib\site-packages\ttfquery-1.0.4-py2.7.egg','C:\ Python27\lib\site-packages\fonttools-2.3-py2.7-win32.egg','C:\ Python27\lib\site-packages\pydispatcher-2.0.2-py2.7.egg','C:\ Python27\lib\site-packages\pyside-1.0.0beta1qt471-py2.7-win32.egg','C:\ code\ots',' C:\ lib\django','C:\ code','C:\ xampp','C:\ Windows\system32\python27.zip','C:\ Python27\L ib','C:\ Python27\DLLs','C:\ Python27\Lib\lib-tk','C:\ xampp\apache\bin','C:\ Users\garethconner\AppData\Roaming\Python\Python27\site-packages','C:\ Python27','C:\ Python27\lib\site-packages','C:\ Python27\lib\site-packages\PIL','C:\ lib\django\django','C:\ Python27\lib\site-packages\win32','C:\ Python27\lib\site-packages\win32\lib','C:\ Python27\lib\site-packages\Pythonwin', 'C:\ Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info','C:\ Python27\lib\site-packages\wx-2.9.1-msw','C: \码']
任何帮助将不胜感激.
我有关于http://code.google.com/p/django-simple-captcha/项目的问题.我按照程序安装验证码,表格有效,但浏览器不加载图片.该怎么办?
我的模式:
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'main.views.main', name="main_page"),
url(r'^registration$', 'main.views.registration', name="registration"),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
# Captcha
url(r'^captcha/', include('captcha.urls')),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^files/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
Run Code Online (Sandbox Code Playgroud) 使用ubuntu 13.10,python 2.7.5:
>>> import _imaging, Image
>>> from PIL import Image, ImageDraw, ImageFilter, ImageFont
>>> im = Image.new('RGB', (300,300), 'white')
>>> draw = ImageDraw.Draw(im)
>>> font = ImageFont.truetype('arial.ttf', 14)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in __init__
self.font = core.getfont(file, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 34, in __getattr__
raise ImportError("The _imagingft C module is not installed")
**ImportError: The …Run Code Online (Sandbox Code Playgroud)