arnoutaertgeerts / python-highcharts

Use highchart.js to make plots in Python and IPython notebooks
http://nbviewer.ipython.org/github/arnoutaertgeerts/python-highcharts/blob/master/Tutorial.ipynb
Other
133 stars 31 forks source link

Python 3 support #37

Open scls19fr opened 9 years ago

scls19fr commented 9 years ago

Hello,

I think python-highcharts doesn't support Python 3

In [1]: import charts
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5eb3a6e89685> in <module>()
----> 1 import charts

//anaconda/lib/python3.4/site-packages/charts/__init__.py in <module>()
      3 __version__ = '0.4.3'
      4
----> 5 from plot import plot, plotasync, line, area, spline, pie
      6 from server import run_server
      7

ImportError: No module named 'plot'

because same import with Python 2 works fine

I'm using Anaconda Python with Python 3 as default Python install and I can switch to Python 2 using

$ source activate py2

Inspired from http://continuum.io/blog/anaconda-python-3

Any idea ?

arnoutaertgeerts commented 9 years ago

@scls19fr If don't really know how to immediately solve this problem but I'm happy to implement it if you found a solution! Let me know or create a pull request :)

joelion commented 9 years ago

The particular ImportError that @scls19fr mentioned can be fixed in python3 by using relative paths to modules, like shown here http://stackoverflow.com/questions/14216200/force-importing-module-from-current-directory

However, after fixing that, there are still many other problems in python3, including all of the print statements and SimpleHTTPServer being replaced by http.server. There may be others, but i'm not sure. Have you tried running the 2to3 tool just to see if that works? https://docs.python.org/2/library/2to3.html I'm not sure how you're supposed to maintain backwards compatibility once you convert to python3, though.

scls19fr commented 9 years ago

six can help to maintain backward compatibility

https://pythonhosted.org/six/

an other approach is to maintain backward compatibility by yourself in a compat.py file with try / except.

Anyway six code can help https://github.com/kelp404/six/blob/master/six.py