我想从Ruby调用Python代码.有一些现有工具可以做到这一点,本网站上的一些问题推荐http://rubypython.rubyforge.org/,它通过在Ruby中嵌入Python解释器来工作.我正在开发一个使用Python独有的库的应用程序(即图形工具,我有理由使用它,比如说RGL),但是最终的项目是在Rails中,因此使用Ruby代码进行控制工作将是理想的.我希望它快速,所以我使用PyPy.有没有办法让PyPy解释器嵌入Ruby代码中,或者在rubypython
运行PyPy时使Python解释器?
做的时候:
$ sudo pypy -m easy_install lxml
Run Code Online (Sandbox Code Playgroud)
回应是:
Searching for lxml
[...snip...]
ERROR: /bin/sh: 1: xslt-config: not found
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
/usr/lib/pypy/lib-python/2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
warning: no files found matching '*.txt' under directory 'src/lxml/tests'
src/lxml/lxml.etree.c:8:22: fatal error: pyconfig.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
同时,sudo pip install …
我正在尝试使用PyPy创建一个服务器端沙箱,对我的文件系统的访问权限有限.我正在使用Ubuntu 12.04 64位机器,并且一直在尝试从这里安装PyPy的完整源代码:http://pypy.org/download.html#sandboxed-version(向下滚动到"从源代码构建"部分).
我的问题是,每当我尝试运行pypy_interact.py(位于pypy/pypy/sandbox)时,我都会收到以下错误:
ImportError:没有名为rpython.translator.sandbox.sandlib的模块
无法导入的模块具有以下路径:pypy/rpython/translator/sandbox/sandlib.py.pypy_interact.py的内容如下:
import sys, os
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), '..\
', '..', '..')))
from rpython.translator.sandbox.sandlib import SimpleIOSandboxedProc
from rpython.translator.sandbox.sandlib import VirtualizedSandboxedProc
from rpython.translator.sandbox.vfs import Dir, RealDir, RealFile
import pypy
LIB_ROOT = os.path.dirname(os.path.dirname(pypy.__file__))
Run Code Online (Sandbox Code Playgroud)
我觉得这是一个非常简单的修复 - 我几天前刚开始学习Python,所以我不确定如何解决问题/不太了解进口.有什么建议?非常感谢.
试图在Ubuntu 14.04上翻译pypy3.我按照这里的说明操作:http://pypy.readthedocs.org/en/latest/getting-started-python.html#installation,但是我收到了一个错误.
pypy ../../rpython/bin/rpython -O2 --sandbox targetpypystandalone.py gives me
File "../../rpython/bin/rpython", line 17
print __doc__
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
查看文件rpython/bin/rpython,我看到一个if语句,我似乎正在点击
if len(sys.argv) == 1:
print __doc__
sys.exit(1)
Run Code Online (Sandbox Code Playgroud)
我没有通过哪些论据我应该是谁?
是否有可能运行Scrapy
的PyPy
?我浏览了文档和github项目,但是PyPy
提到的唯一地方是PyPy
2年前正在执行一些单元测试,请参阅PyPy
support。Scrapy在PyPy中也失败了,3年前的漫长讨论没有具体的决议或后续行动。
据我了解,主要Scrapy的依赖Twisted
是众所周知的工作PyPy
。Scrapy还lxml
用于HTML解析,它具有一个PyPy
友好的fork。pyOpenSSL
完全支持另一个依赖项(由于@Glyph的注释)。
我听说过关于PyPy的好东西.特别是我听说它非常快,这让我想知道它是否可用于我拥有的嵌入式项目.
我下载PyPy-2.6
了我的Windows 7
电脑,并将内容解压缩到一个目录中.
我写了一个小测试程序,允许我进行基准测试:
import time
def fib(n):
if n == 0 or n == 1:
return 1
return fib(n - 1) + fib(n - 2)
t0 = time.time()
fib(20)
t1 = time.time()
print t1-t0
所以我去了PyPy解压缩的目录,运行./pypy.exe hello.py
并得到答案0.120
.
然后我启动了一个cygwin控制台并运行python hello.py
并得到了答案0.01
.
我使用PyPy是错误的还是只对某些应用程序更快?
编辑
感谢Rob指出JIT编译器需要时间来预热.
扩展我的示例代码会产生以下结果:
n PyPy Python 20 0.12 0.01 25 0.15 0.06 30 0.34 0.67 35 0.92 7.39 40 10.98 82.9
似乎有0.1秒的启动成本或其他东西,但之后它会更快.
我使用以下方法为PyPy创建了virtualenv:
virtualenv test -p `which pypy`
source test/bin/activate
Run Code Online (Sandbox Code Playgroud)
我安装了以下依赖项:
sudo apt-get install python-dev libxml2 libxml2-dev libxslt-dev
Run Code Online (Sandbox Code Playgroud)
然后我运行:
pip install --upgrade pypy
Run Code Online (Sandbox Code Playgroud)
结果,我收到了很多如下所示的错误:
src/lxml/lxml.etree.c:234038:22: error: `PyThreadState` {aka struct _ts}` has no member named `use_tracing`
Run Code Online (Sandbox Code Playgroud)
如何为PyPy 2.6.0正确安装lxml?
这个问题与将numpy与pypy一起使用有关
我尝试使用
点安装git + https://bitbucket.org/pypy/numpy.git
该系统(Fedora版本24(二十四))表示
git:“ submodule”不是git命令。参见'git --help'。命令“ git子模块更新--init --recursive -q”失败,错误代码为/ tmp / pip-LD8rrP-build
似乎numpy与pypy不兼容。
这个问题有什么解决办法吗?PS我设法在ubuntu上安装了它,但是没有在fedora上安装。
附加信息:
Fedora第24版(二十四)
来自/usr/lib/python2.7/site-packages(python 2.7)的pip 9.0.1
git版本2.7.4
我在Ubuntu 14.04上使用PyPy 2.2.1。
我想xlrd
为我的程序使用模块,但是用pypy运行程序会导致导入错误。我该如何解决?
解决了最近出现的代码问题,我发现我的默认Python比PyPy慢约40倍.通过在函数中运行限制调用和限制全局查找,我能够通过此代码将其降低到大约17倍len
.
现在,e.py
在python 3.6.3上运行5.162秒,在我的机器上在PyPy上运行.297秒.
我的问题是:这是JIT的不可缩短的加速,还是有某种方法可以加速CPython的回答?(没有极端的意思:我可以去Cython/Numba或其他什么?)我如何说服自己,我无能为力?
请参阅gist以获取数字输入文件列表.
如问题陈述中所述,它们代表跳跃偏移.position += offsets[current]
,并将当前偏移量增加1.当跳转将您带到列表外时,您就完成了.
这是给出的示例(需要5秒的完整输入更长,并且具有更大的数字):
(0) 3 0 1 -3 - before we have taken any steps.
(1) 3 0 1 -3 - jump with offset 0 (that is, don't jump at all). Fortunately, the instruction is then incremented to 1.
2 (3) 0 1 -3 - step forward because of the instruction we just modified. The first instruction is incremented again, …
Run Code Online (Sandbox Code Playgroud) pypy ×10
python ×7
lxml ×3
benchmarking ×1
git ×1
numpy ×1
performance ×1
python-2.7 ×1
ruby ×1
sandbox ×1
scrapy ×1
twisted ×1
xlrd ×1