From: Dale L. P. <haz...@gm...> - 2012-10-31 18:29:05
|
> import loops: if you have a chance, Luke, can you try out Scott's change and see if it works on python 3. I'll try to install it over the weekend and try it myself, but would be good to get another check. I applied Scott's change to revision 211, then ran: $ find . -name "*.py" -exec 2to3 -w {} \; Then I built and installed it and when I import it, it gives me this error: 11:17:33 ~$ python Python 3.2.3 (default, Sep 30 2012, 09:06:04) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import control Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/hazelnusse/usr/lib64/python3.2/site-packages/control-0.6a-py3.2.egg/control/__init__.py", line 60, in <module> from .bdalg import series, parallel, negate, feedback File "/home/hazelnusse/usr/lib64/python3.2/site-packages/control-0.6a-py3.2.egg/control/bdalg.py", line 55, in <module> from . import xferfcn as tf File "/home/hazelnusse/usr/lib64/python3.2/site-packages/control-0.6a-py3.2.egg/control/xferfcn.py", line 84, in <module> from .statesp import StateSpace File "/home/hazelnusse/usr/lib64/python3.2/site-packages/control-0.6a-py3.2.egg/control/statesp.py", line 85, in <module> from .xferfcn import TransferFunction ImportError: cannot import name TransferFunction >>> So 2to3 is converting "from xferfcn import TransferFunction" to "from .xferfcn import TransferFunction", which for some reason does not work. I think the reason it does not work has to do with the __init__.py file as well as the __all__ variable not being set in each module (i.e., statesp.py and xferfcn.py). > > Is anyone ensuring that running the 2to3 tool is sufficient for use of python-control with Python 3, or otherwise working on a script that makes necessary changes? I have apparently verified that it isn't. Sympy uses a script called "use2to3" which runs 2to3 on most (but not all) of the source python files and generates a new source tree in a folder called "py3k-sympy" that contains the converted files. You then build and install sympy from that folder using python3. You can see how they do it here: https://github.com/sympy/sympy/blob/master/bin/use2to3 > > While that design pattern is nice, it may not yet be warranted for python-control, which is contained entirely in a single directory with no subpackages. The simplest change I see to avoid the import error you found is below (given as diff output). True. I'm not certain what the "best" way to do this is either, I just know what has worked for me in another project across many different versions of Python. Luke |