I have been using pypy 1.4 which is said to be fully compatible with cpython 2.5 but when I try to import the curses module, I get an import error evn though the curses module is available.Any pointers why this may be happening?
The curses Python module uses the _curses C module.
The PyPy Python compatibility page says the following (with points emphasized by me):
PyPy implements the Python language version 2.5. It supports all of the core language, passing Python test suite (with minor modifications that were already accepted in the main python in newer versions). It supports most of the commonly used Python standard library modules; details below.
PyPy has alpha-level support for the CPython C API, however, as of 1.4.1 release this feature is not yet complete. Most libraries will require a bit of effort to work, but there are known success stories. Check out PyPy blog for updates.
C extensions need to be recompiled for PyPy in order to work. Depending on your build system, it might work out of the box or will be slightly harder. In order to instruct pypy to load a CPython extension (compiled with supplied Python.h), run following line:
import cpyext
Further down that page, there is a list of standard library modules supported by PyPy. I don't see curses there, although there is a _minimal_curses which might be of use to you.
Here is the bug report.
Related
I want to develop and test my project on the up-to-date version of Python 2.7 (say 2.7.18), but I want my project to be still fully usable on earlier versions of 2.7 (say 2.7.7). Setting up many variants of 2.7 locally or/and on CI for testing can be redundant.
So there are the following questions about compatibility of 2.7.X.
Can there be any changes in syntax which make code not working?
Can there be any changes in available standard imports, for example, can some imports from __future__ be unavailable in earlier versions?
Since I have to distribute compiled Python files (.pyc, compiled via py_compile module), I'm also wondering if there can be any changes in Python bytecode which block code execution in earlier versions.
I guess if all the answers are "no", I can develop and test my project only on a single 2.7 version without worries.
I've tried to search it but there is no success. Please share your experience and/or links.
UPD 1: I should have clearly said from the beginning that it's not my desire to use 2.7, it's a requirement from the environment.
At least Python 2.7.9 introduced massive changes to the 'ssl' module, so trying to use code using SSL for 2.7.18 on Python older than 2.7.9 will fail. So a clear "yes" to number 2.
In general compatbility for most projects works the other way round, use the oldest version you need to support and work upwards from old to new, not downwards from newer to older. I do not know of any software project that makes the guarantees in the other direction.
Note that Python 2.7 dropped out of support with 2.7.18, so unless you use a compatible version like PyPy (https://www.pypy.org/) your freshly developed project will run on outdated Python versions from the start.
If you want to provide a shrink wrapped product, maybe have a look at the usual solution for this like pyinstaller (https://www.pyinstaller.org/) or freeze (https://wiki.python.org/moin/Freeze)
The #3 may work, if you study the list of bytecode opcodes which do not change that much over time (https://github.com/python/cpython/commits/2.7/Include/opcode.h) but no idea if the on-disk format changed.
Frank Wierzbicki in his blog post has written "Jython 2.7b3 brings us up to language level compatibility with the 2.7 version of CPython."
Does it mean that any CPython 2.7 code would work with Jython?
I have a large code written in CPython 2.7. Since we want to integrate it with JAVA modules, I would be extremely interested in a way of migrating to Jython without rewriting of code. Considering libraries, I use a lot of lxml which (as described here) was not compatible with the previous versions Jython.
No, not all code that works in CPython 2.7 will work in Jython, in the same way that some code is tied to a specific OS and won't work on other OS-es (e.g. Windows-specific Python code won't work on Linux, and vice versa).
The syntax will work, but if the script requires specific add-on modules such as lxml, then those will not work. That is because lxml is a C-API extension, and Jython doesn't support the Python C-API.
Similarly, if your code uses the multiprocessing module, then it also won't work on Jython, because that part of the standard library is not included.
I'm looking to call Python code from Ruby. There are a few existing tools to do this and a few questions on this site recommending http://rubypython.rubyforge.org/, which works by embedding the Python interpreter in Ruby. I'm working on an app that uses libraries unique to Python (namely graph-tool, which I have reasons for using over, say RGL), but the final project is in Rails so having Ruby code do the controlling work would be ideal. I want it to be speedy so I'm using PyPy. Is there a way to get the PyPy interpreter embedded in Ruby code, or to make the Python interpreter in rubypython run PyPy?
No. Well, not without a lot of work.
First, RubyPython doesn't really include an embedded Python interpreter; it just wraps the interpreter at runtime. As shown in the docs, you can run it with any Python you want, e.g.:
>> RubyPython.start(:python_exe => "python2.6")
So, what happens when you try?
>> RubyPython.start(:python_exe => "/usr/local/bin/pypy")
RubyPython::InvalidInterpreter: An invalid interpreter was specified.
from /Library/Ruby/Gems/1.8/gems/rubypython-0.6.3/lib/rubypython.rb:67:in `start'
from /Library/Ruby/Gems/1.8/gems/rubypython-0.6.3/lib/rubypython/python.rb:10:in `synchronize'
from /Library/Ruby/Gems/1.8/gems/rubypython-0.6.3/lib/rubypython/python.rb:10:in `synchronize'
from /Library/Ruby/Gems/1.8/gems/rubypython-0.6.3/lib/rubypython.rb:54:in `start'
from (irb):4
Unfortunately, it requires CPython 2.4-2.7. It doesn't work with CPython 3.x, PyPy, Jython, etc. Again, from the docs:
RubyPython has been tested with the C-based Python interpreter (cpython), versions 2.4 through 2.7. Work is planned to enable Python 3 support, but has not yet been started. If you’re interested in helping us enable Python 3 support, please let us know.
Without looking at the code, I'm guessing rubypython is using rubyffi to either:
* Wrap the CPython embedding APIs, or
* Directly call CPython VM internals via its dll/so/dylib exports.
If it's the former, the project might be doable, but still a lot of work. PyPy doesn't support CPython's embedding APIs. If it had its own embedded APIs, you could potentially rewrite rubypython's lower level to wrap those instead, and leave the higher-level code alone. But embedding PyPy at all is still a work in progress, (See http://mail.python.org/pipermail/pypy-dev/2012-March/009661.html for the state of affairs 6 months ago.) So, you'd need to first help get PyPy embedding ready for prime time and stable, and then port the lower level of rubypython to use the different APIs.
If it's the latter, you're pretty much SOL. PyPy will never support the CPython internals, and much of what's internal for CPython is actually written in RPython or Python and then compiled for PyPy, so it's not even possible in principle. You'd have to drastically rewrite all of rubypython to find some way to make it work, instead of just porting the lower level.
One alternative is to port Ruby to RPython and use PyPy to build a Ruby interpreter and a Python interpreter that can talk to each other at a higher level; then, writing something like rubypython for PyRuby and PyPy would be trivial. But that first step is a doozy.
Is there a difference in python programming while using just python and while using pypy compiler? I wanted to try using pypy so that my program execution time becomes faster. Does all the syntax that work in python works in pypy too? If there is no difference, can you tell me how can i install pypy on debian lunux and some usage examples on pypy? Google does not contain much info on pypy other than its description.
From the pypy features page:
PyPy 1.9 implements Python 2.7.2 and runs on Intel x86 (IA-32) and
x86_64 platforms, with ARM and PPC being underway. It supports all of
the core language, passing the Python test suite.
This means that pretty much any code that you've written in Python 2.7 will work. The only exceptions worth mentioning are some python extensions written in C, such as numpy.
Installation should be fairly easy, you can download a linux binary from here. Then simply extract the interpreter. From this point, you can run your python programs similar to how you would run them with the normal python interpreter.
At the command line, instead of:
python my_program.py
Use:
path/to/where/you/installed/pypy my_program.py
For examples of how/why you might want to use pypy, check out this video from PyCon 2012.
pypy is a compliant alternative implementation of the python language. This means that there are few (intentional) differences. One of the few differences is pypy does not use reference counting. This means, for instance, you have to manually close your files, they will not be automatically closed when your file variable goes out of scope as in CPython.
I am using Python 2.5.2. How can I tell whether it is CPython or IronPython or Jython?
Another question: how can I use a DLL developed in VB.NET in my project?
import platform
platform.python_implementation()
The above one provide the type of interpreter you use .
If you downloaded it as the default thing from python.org, it's CPython. That's the “normal” version of Python, the one you get when you use the command “python”, and the one you'll have unless you specifically went looking for the projects targeting Java/CIL.
And it's CPython because neither of the other projects have reached version number 2.5.2.
How can i use a dll developed in VB.NET in to my project?
From CPython, using Python-for-.NET(*) and clr.AddReference.
(*: actually a bit of a misnomer, as with CPython in control it is more like .NET-for-Python.)
If you are typing "python" to launch it, it is probably CPython. IronPython's executable name is "ipy".
import sys
print sys.version
Well since the first part of your question has been answered, I'll tackle the second part. .NET dll's can be accessed from python in various ways. If you are using ironpython it makes this especially easy, since all .NET languages can interact with eachother fairly seamlessly. In this case you would access your dll from ironpython just as you would any other .NET dll you made with ironpython. If you want to call a native dll you can use ctypes.