Can I embed CPython inside PyPy?

2019-04-09 22:05发布

I'd like to write a performance-sensitive application in Python, so executing it under PyPy is a natural choice. However, a significant portion of my code depends on numpy, scipy, and scikit-learn. Would it be possible to embed a CPython instance within a running PyPy program in order to call array-oriented code? If not, what's the easiest way to make PyPy and CPython talk to each other?

2条回答
太酷不给撩
2楼-- · 2019-04-09 22:26

Your best bet for the time-being is Cython rather than PyPy. It has c-level performance, if you add type declarations, and excellent integration with numpy, et al.

People are currently working on getting it to work well with PyPy, but that's a ways off yet.

查看更多
叛逆
3楼-- · 2019-04-09 22:27

No, you can't embed CPython inside PyPy AFAIK. You can, however, use distributed/parallel execution systems to make PyPy talk to CPython. Both execnet and Pyro mention this precise PyPy <-> CPython use case. Other packages from Python Wiki's Parallel Processing page are probably suitable too.

Also, as delnan mentions, there's a current discussion about PyPy developers' plan on implementing Numpy in PyPy (which doesn't include support for scipy, and scikit.learn so far).

查看更多
登录 后发表回答