toyz icon indicating copy to clipboard operation
toyz copied to clipboard

Python 3 support?

Open cdeil opened this issue 9 years ago • 8 comments

I wanted to try out toyz and ran into this error:

$ python setup.py install --user
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    from toyz import version
  File "/Users/deil/code/toyz/toyz/__init__.py", line 1, in <module>
    import web
ImportError: No module named 'web'

This would be easy to fix – use explicit relative imports or absolute imports.

@fred3m Do you think Python 3 support would be easy to achieve for toys or are there some tricky parts that only work on Python 2?

cdeil avatar Apr 20 '15 19:04 cdeil

Hmmmm, I'm not sure what the problem is here. I've been developing un Python 2.7 so I haven't tried Python 3, however I have been trying along the way to make everything compatible, so there shouldn't be too much that needs changing. At first glance, I wonder if this is the issue discussed here.

fred3m avatar Apr 20 '15 20:04 fred3m

The issue is that you are using "implicit relative imports" which are not supported in Python 3 any more. You should use "explicit relative imports":

import .web

or

from . import web

or "absolute imports":

from toyz import web

This is a short explanation: https://www.python.org/dev/peps/pep-0008/#imports This is a nice but long explanation: https://www.youtube.com/watch?v=0oTh1CXRaQ0

If it's not fixed already we could sprint on Python 3 support for toyz tomorrow.

cdeil avatar Apr 20 '15 20:04 cdeil

Thanks, I've been using absolute imports for most of the modules, I think that for whatever reason I just neglected to do that for the init.py files. I fixed this in both Toyz and Astro-Toyz but haven't had time to setup a Python 3 environment in Anaconda to test tonight.

fred3m avatar Apr 20 '15 20:04 fred3m

By now the install works with Python3, but there's this issue:

$ toyz
Loading dependencies, please wait...
Traceback (most recent call last):
  File "/Users/deil/Library/Python/3.4/bin/toyz", line 4, in <module>
    __import__('pkg_resources').run_script('toyz==0.0.dev0', 'toyz')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 723, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources/__init__.py", line 1636, in run_script
    exec(code, namespace, namespace)
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/toyz-0.0.dev0-py3.4.egg/EGG-INFO/scripts/toyz", line 7, in <module>
    from toyz.web.app import init_web_app
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/toyz-0.0.dev0-py3.4.egg/toyz/__init__.py", line 1, in <module>
    from toyz import web
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/toyz-0.0.dev0-py3.4.egg/toyz/web/__init__.py", line 1, in <module>
    from toyz.web import app
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/toyz-0.0.dev0-py3.4.egg/toyz/web/app.py", line 24, in <module>
    from toyz.utils import core
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/toyz-0.0.dev0-py3.4.egg/toyz/utils/__init__.py", line 7, in <module>
    from toyz.utils import core
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/toyz-0.0.dev0-py3.4.egg/toyz/utils/core.py", line 12, in <module>
    import cPickle as pickle
ImportError: No module named 'cPickle'

cdeil avatar Apr 29 '15 09:04 cdeil

Thanks for the update. This is because in Python 3 pickle is cPickle. I fixed problem in the repo, thanks for being my Python 3 alpha tester.

fred3m avatar Apr 29 '15 12:04 fred3m

You should make travis-ci.org your tester ... it's super-useful to have.

Even just checking that python setup.py install and imports work with Python 2 / 3 is useful. Then to make it really useful you'd have to implement tests. Either by programatically calling your functions / classes, or if needed a full end-user app test via https://selenium-python.readthedocs.org/ It's a lot of work to set up, but does pay off in the long run ...

cdeil avatar Apr 29 '15 13:04 cdeil

You can ping me for any questions about .travis.yml or weird error messages, I have some experience deciphering those ...

cdeil avatar Apr 29 '15 13:04 cdeil

I agree, that's a good idea that will have to wait for me to have more time to implement. Between myself and collaborators I have 3 observing runs in May that I'm preparing for. On Apr 29, 2015 9:11 AM, "Christoph Deil" [email protected] wrote:

You can ping me for any questions about .travis.yml or weird error messages, I have some experience deciphering those ...

— Reply to this email directly or view it on GitHub https://github.com/fred3m/toyz/issues/7#issuecomment-97421525.

fred3m avatar Apr 29 '15 13:04 fred3m