标签: pypy

如何在PyPy中使用PIL?

我搜索了一下但我找不到一个tuto使用PIL和PyPy.根据PyPy的博客,PIL得到了支持.

  • 我在PYTHONPATH中安装了PIL.
  • 下载后,pip制作2个.pyd文件:_imaging.pyd和_imagingmath.pyd.
  • 安装完成后,我将%PYTHONPATH%/ lib/site-packages/PIL复制到我的PyPy site-packages目录.
  • 当我运行我的脚本(使用PIL)时,它说它无法导入_imaging C模块.

我该怎么办?

编辑:我在Windows 7 x64(python 2.7.1 32bits)上运行

这里是追溯(pypy 1.4.1 windows二进制):

Traceback (most recent call last):
  File "app_main.py", line 53, in run_toplevel
  File "tools\python\gen_images.py", line 52, in <module>
    main()
  File "tools\python\gen_images.py", line 44, in main
    image = Image.open(file)
  File "d:\pypy\site-packages\PIL\Image.py", line 1965, in open
    return factory(fp, filename)
  File "d:\pypy\site-packages\PIL\ImageFile.py", line 91, in __init__
    self._open()
  File "d:\pypy\site-packages\PIL\GifImagePlugin.py", line 97, in _open
    self.seek(0) # get ready to read first frame
  File "d:\pypy\site-packages\PIL\GifImagePlugin.py", line 152, in seek …
Run Code Online (Sandbox Code Playgroud)

python pypy python-imaging-library

8
推荐指数
1
解决办法
8109
查看次数

为什么CPython在两个测试"slowspitfire"和"waf"上比PyPy更快?

从PyPy Speed Center上发布的基准测试来看,似乎除了两个测试之外的所有测试,PyPy比CPython更快.

在两个测试"slowspitfire"和"waf"中,CPython比PyPy更快.这是为什么?这两项测试测试的是哪种操作?是什么让CPython更快地进行这些操作?PyPy能否在这两项测试中赶上并击败CPython?

python benchmarking pypy cpython

8
推荐指数
1
解决办法
1207
查看次数

PyPy - SWIG - QuickFix混音

PyPy有一些兼容性限制,特别是关于CPython C API.

我使用QuickFix包附带预编译的SWIG绑定,我正在考虑将它与PyPy一起使用.由于我不熟悉C API和SWIG,我的问题是:

  • PyPy的C API兼容性限制是否会妨碍SWIG的工作?你能解释一下原因吗?
  • 我是否需要重新编译SWIG绑定才能使用PyPy?那可能吗?怎么样?

swig pypy quickfix python-bindings

8
推荐指数
1
解决办法
1430
查看次数

安装Python时,使用pypy easy_install

我在我的系统上安装了Python 2.7时安装了PyPy.

  • 如何安装然后使用easy_installPyPy?
  • 区分我要安装到哪里的语法是什么easy_install
  • 我应该设置任何环境变量以方便使用吗?

我在Windows上,但这些问题似乎与所有平台相关......

python pypy setuptools easy-install distribute

8
推荐指数
2
解决办法
7531
查看次数

RPython sys方法不起作用

我有以下代码:

import sys

def entry_point(argv):
    sys.exit(1)
    return 0

def target(*args):
    return entry_point, None
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时,python ./pypy/pypy/translator/goal/translate.py t.py我收到以下错误:

...
[translation:ERROR]  Exception: unexpected prebuilt constant: <built-in function exit>
[translation:ERROR] Processing block:
[translation:ERROR]  block@9 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'>
[translation:ERROR]  in (t:3)entry_point
[translation:ERROR]  containing the following operations:
[translation:ERROR]        v0 = simple_call((builtin_function_or_method exit), (1))
[translation:ERROR]  --end--
Run Code Online (Sandbox Code Playgroud)

实际上有更多的错误,但我认为只有最后一部分是相关的.如果你认为它可能会有所帮助,请发表评论,然后我会编辑.

实际上,当我将sys.exit替换为更简单的类似sys.stdout.write时,我会遇到另一个错误.

import sys

def entry_point(argv):
    sys.stdout.write('some mesg\n')
    return 0

def target(*args):
    return entry_point, None
Run Code Online (Sandbox Code Playgroud)

给我:

...
[translation:ERROR]  AnnotatorError: annotation of v0 degenerated to SomeObject()
[translation:ERROR] v0 = …
Run Code Online (Sandbox Code Playgroud)

python pypy rpython

8
推荐指数
1
解决办法
452
查看次数

使用pypy编译器

使用python和使用pypy编译器时,python编程是否有区别?我想尝试使用pypy,以便我的程序执行时间变得更快.在python中工作的所有语法是否也在pypy中工作?如果没有区别,你能告诉我如何在debian lunux上安装pypy以及pypy上的一些使用示例?谷歌除了描述之外没有太多关于pypy的信息.

python pypy python-2.7 python-3.x

8
推荐指数
1
解决办法
7305
查看次数

PyCharm和Pypy - 未解决的参考

出于一些奇怪的原因,我的PyCharm喜欢到处显示未解决的错误.
但只有pypy.源代码运行得很好,即使PyCharm可以完美运行代码.

但到处都是红线真的很烦人.
问题:http://i.imgur.com/o5BqCZP.jpg

Ps.:我尝试了Invalidate缓存方法,但它没有帮助.

python pypy pycharm

8
推荐指数
1
解决办法
2688
查看次数

在PyPy下使用__slots__

我有这个简单的代码帮助我测量类的__slots__执行方式(从这里开始):

import timeit

def test_slots():
    class Obj(object):
        __slots__ = ('i', 'l')

        def __init__(self, i):
            self.i = i
            self.l = []

    for i in xrange(1000):
        Obj(i)

print timeit.Timer('test_slots()', 'from __main__ import test_slots').timeit(10000)
Run Code Online (Sandbox Code Playgroud)

如果我通过python2.7运行它 - 我会在6秒左右得到一些东西 - 好吧,它比没有插槽时更快(并且内存效率更高).

但是,如果我在PyPy下运行代码(使用2.2.1 - 64位用于Mac OS/X),它开始使用100%CPU并且"从不"返回(等待几分钟 - 没有结果).

到底是怎么回事?我应该__slots__在PyPy下使用吗?

如果我传递不同的数字,会发生什么timeit():

timeit(10) - 0.067s
timeit(100) - 0.5s
timeit(1000) - 19.5s
timeit(10000) - ? (probably more than a Game of Thrones episode)
Run Code Online (Sandbox Code Playgroud)

提前致谢.


请注意,如果我使用namedtuples,则会观察到相同的行为:

import collections
import timeit …
Run Code Online (Sandbox Code Playgroud)

python performance pypy slots

8
推荐指数
2
解决办法
868
查看次数

为什么JIT代码比编译代码或解释代码消耗更多内存?

编译代码如C消耗很少的内存.

解释代码如Python消耗更多内存,这是可以理解的.

使用JIT,程序在运行时(有选择地)编译为机器代码.那么JIT的程序的内存消耗应该介于编译程序和解释程序之间吗?

相反,JIT的程序(例如PyPy)消耗的内存比等效的解释程序(例如Python)多几倍.为什么?

compiler-construction jit programming-languages pypy

7
推荐指数
2
解决办法
1771
查看次数

Unicode,正则表达式和PyPy

我编写了一个程序来为Python正则表达式添加(有限的)unicode支持,虽然它在CPython 2.5.2上工作正常,但它不适用于PyPy(1.5.0-alpha0 1.8.0,实现Python 2.7.1 2.7.2),两者都运行在Windows XP上(编辑:如评论中所示,@ dbaupp可以在Linux上正常运行).我不知道为什么,但我怀疑它与我对u"和的使用有关ur".完整的源代码在这里,相关的位是:

# -*- coding:utf-8 -*-
import re

# Regexps to match characters in the BMP according to their Unicode category.
# Extracted from Unicode specification, version 5.0.0, source:
# http://unicode.org/versions/Unicode5.0.0/
unicode_categories = {
    ur'Pi':ur'[\u00ab\u2018\u201b\u201c\u201f\u2039\u2e02\u2e04\u2e09\u2e0c\u2e1c]',
    ur'Sk':ur'[\u005e\u0060\u00a8\u00af\u00b4\u00b8\u02c2-\u02c5\u02d2-\u02df\u02...',
    ur'Sm':ur'[\u002b\u003c-\u003e\u007c\u007e\u00ac\u00b1\u00d7\u00f7\u03f6\u204...',
    ...
    ur'Pf':ur'[\u00bb\u2019\u201d\u203a\u2e03\u2e05\u2e0a\u2e0d\u2e1d]',
    ur'Me':ur'[\u0488\u0489\u06de\u20dd-\u20e0\u20e2-\u20e4]',
    ur'Mc':ur'[\u0903\u093e-\u0940\u0949-\u094c\u0982\u0983\u09be-\u09c0\u09c7\u0...',
}

def hack_regexp(regexp_string):
    for (k,v) in unicode_categories.items():
        regexp_string = regexp_string.replace((ur'\p{%s}' % k),v)
    return regexp_string

def regex(regexp_string,flags=0):
    """Shortcut for re.compile that also translates and …
Run Code Online (Sandbox Code Playgroud)

python regex string unicode pypy

7
推荐指数
2
解决办法
745
查看次数