I'm trying to get some python code I've written earlier on Windows to work on my DS. I'm using (DSPython), and when I tried to import math, it failed with "ImportError: No module named math". I've gotten most all other modules I need that don't rely on math working. But math is normally a builtin module, so I can't just find math.py on my PC and copy it over. Any suggestions on where I can find an alternative to the builtin math module that can still perform the same functions?
Asked
Active
Viewed 2,029 times
3
-
Have you tried contacting the DSPython developer? It may be that he's just not gotten to it yet. Expressing interest (and a willingness to help) might get you enough information to get it going yourself. – Michael Kohne Jan 26 '10 at 14:28
-
3The project hasn't been touched in over 16 months. But the source is available. But from reading the documentation, it looks very messy. The author warns you that when following his build process, several programs will crash or fail with errors, and that you should simply ignore them. He also explains how everything is hacked together, and attempting to change any file could result in unexpected results. It looks to me like adding any new functionality and rebuilding would be a nightmare. At this point, I'm leaning towards making my own math module in Python. But I'll accept any easier method. – Ponkadoodle Jan 27 '10 at 03:53
-
1It would all depend on how much methods of the math module you need. If it's only `math.sqrt` (or something similar) than you could simply do `sqrt = lambda x: x ** (1./x)`. If you need lots of functions and/or fast versions than you really should try to cross-compile it. I have cross-compiled a lot of software for the NDS and with the right toolchain it's not that hard. I've even written programs to crack wep/wpa (speedtouch) networks which requires a lot of math. For my efforts I used DSLinux which also allows you to run Python. – Wolph Mar 12 '10 at 01:43
-
Awesome! I figured that you'd be able to run Python through DSLinux, but I'm not familiar enough with Linux to get it setup. Can you point me to a tutorial? Speed is not an issue. But, I need to use the random module, which requires lots of math functions.(Also, I believe `sqrt(x) = x ** 0.5`) – Ponkadoodle Mar 12 '10 at 02:06
-
@WoLpH (I think I need to address my post to WoLpH for SO to treat it as a reply to him) – Ponkadoodle Mar 17 '10 at 22:00
-
Yes, indeed. The @WoLpH helps ;) The first part is simply following this tutorial: http://dslinux.org/cgi-bin/moin.cgi/RunningDSLinux After that... the difficult part starts, you'll have to cross-compile Python. You can use the porting tutorial for setting up the toolchain and compiling python: http://dslinux.org/cgi-bin/moin.cgi/PortingHowto As for the sqrt... you're completely right, it was obviously late when I wrote that reply ;) – Wolph Mar 18 '10 at 00:21
2 Answers
1
Last month dspython has been given an overall project cleanup, and several issues, including the one you mention, were addressed in the process.
If you're still interested in running that Python code in your DS, this is a good time to try again. A contributor has also written some small example programs, that are good starting points for you to use - they also can give you an idea of what's implemented so far.

Lorenzo Mancini
- 15
- 5
0
Your best bet would be to wrap the NDS c library with pyrex, and create your own math module. The rest of dspython is.

George Griffin
- 634
- 7
- 17