How can I run Python on my HP Prime graphing calculator?

Viewed 4738

According to this firmware post, the HP Prime graphing calculator supports Python. However, I cannot find any guide as to how to run python files in the calculator (even within HP's own 700 page long user manual). Does anyone know how to execute these files?

  • For reference, I have HP Prime's connectivity kit (CK) installed, so I am somewhat able to transfer python code (by copy-pasting into CK's "Programs" section). However, I think it's reading it as Prime Programming Language instead, as it does not run.

Edit: HP Prime has rebooted and now there is a Python app, allowing me to run some files. Unfortunately, I cannot access any Python libraries. That is, I can only run files that do not have "import _____" in them. This seems like a problem; anyone know how to resolve?

Also a further problem is that the files are not actually saved in my calculator, as far as I can tell.

3 Answers

i have the firmware update installed on my daughter's HP Prime and it works. After installing the firmware i was able to create with the connectivity kit a Python application first which then is transfered in 'Program' under the name Python (app) with a pretty Python icon aside. This python app can be edited and i can test it,example:

def it():
  x=exp(3)
  return x

if i run it in the CAS:

it()

e^3

you will notice there is no need for importing exp from math and that the result is computed symbolically ! but it works.

For python coding i prefer to use another method: after the firmware update there is a new HP application when pressing 'Apps' you have now Python,clik on it and it will create a new main.py file you can edit. Editing can be done by clicking on 'Symb' key,example to test math import:

from math import *

x=exp(3)
print(x)

now click on 'Num' key to go to the Python console, the HP will run automatically the main.py code:

import main

20.0855369231877

you can type other command like : from main.py import function2import

The Python app have a lot of features in the sub menus:

Templt contains a lot of Python syntax

Cmds contains a lot of import and functions to use.

Enjoy! the only caveat i dislike is the lack of syntax highlightning in color like on other calculators. Perheaps in another update!

I couldn't really find a good source to read about Python support in this particular brand, but in general, graphing calculators have much more limited memory than personal computers, so they do not choose CPython or any of the heftier implementations of the Python language. They will instead use lightweight implementations like MicroPython or CircuitPython (not these ones exactly but maybe a derivation).

These implementations don't have the full standard library of CPython and can have different modules particular to their intended contexts. There probably ARE some modules you can use, but without proper documentation it's hard to say which. It may go without saying but you are certainly restricted from downloading arbitrary Python libraries.

i struggled a lot with python on the hp prime as well. I would suggest to look the libs up inside the calculator. (Apps->Python->Cmds->7.math->from math import *) You can see all the commands like pi, sqrt, ... as well) I dont know if i got it right but i can give you another example how i did the coding. [HP CK1][1]

[HP CK2][2] Main

Export ppl()
Begin
  Your_Function();
End;

Your_Function

#PYTHON EXPORT Your_Function()

from math import *

U_z=float(input("U_z: "))
print(U_z)
U_rz=float(input("U_rz: "))
print(U_rz)
degr=float(input("degr: "))
print(degr)
freq=float(input("freq: "))
print(freq)

print(pi*sqrt(freq))

#end

To execute it go to Apps->Press "Shift"+"Program" to open the Program Catalog. Navigate to your script name. Press "Run" on the buttom right on your screen and hope for no error. ;) [1]: https://i.stack.imgur.com/cgG0w.png [2]: https://i.stack.imgur.com/H25Sd.png

Related