User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

numpy

Sat Jan 23, 2021 6:26 pm

Does anyone know how to install the numpy library in Thonny? I'm getting this error:

Installing to temp directory
Error installing 'numpy==1.19.5': , packages may be partially installed
Installing to: /var/folders/43/v1d780lj3dvff3z8g6t_qphr0000gn/T/tmpl3d3osg2/
Warning: pypi.org SSL certificate is not validated

micropip returned with error code 1

rwcooper
Posts: 77
Joined: Wed Dec 30, 2015 9:04 pm
Location: Winnipeg, Canada

Re: numpy

Sat Jan 23, 2021 7:13 pm

What command are you using? I did sudo apt -y install python3-numpy and Thonny was able to use it. Are you trying to install numpy in Micropython?

User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

Re: numpy

Sat Jan 23, 2021 10:41 pm

Hi rwcooper

I'm running Thonny (which I am totally new to) on a MacBook, and I was using the Tools/Manage Packages or Manage Plug-ins to load the libraries. It seems to find the relevant package and even shows it as now installed in Manage Plug-ins which doesn't seem to be relevant for creating MicroPython for the Pico. I just realised it's the Manage Packages I need for the MicroPython and that's where I am getting that certificate error. Stopping Thonny and restarting it after the download as recommended doesn't allow my MicroPython code to load numpy. The same also applies to another library - matplotlib.pylab which also gets the certificate error. As I said, I'm new to using Thonny. I also have an RPi400 which I could use for programming the Pico, so I"m sure I could then use the apt-install commands.
If anyone knows how to do it on a Mac, that is currently my preferred option.

Tony

User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

Re: numpy

Sat Jan 23, 2021 11:57 pm

A google search suggested using "pip install certifi" at the terminal to install the required SSL certificate package, but that didn't work either.
I also typed pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org numpy -vvv. That installed numpy for the Mac, but not where Thonny could pick it up for programming the Pico. The trouble is I don't understand the structure of all this, so I am typing in the dark.

Tony

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 345
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: numpy

Sun Jan 24, 2021 12:25 am

Someone was asking how to add a native C implemented python module to the RP2040 version of MicroPython, so I started this branch

https://github.com/raspberrypi/micropyt ... ed0a95a258

The example I used (in the comments) ulab I believe include numpy

So if you're feeling adventurous you can build that!

User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

Re: numpy

Sun Jan 24, 2021 9:21 am

Hi Kilograham

I had a look at your github link, but AKAIK that doesn’t help a beginner wanting to use the ‘approved’ Thonny on a Mac. I think the problem is to do with the latest Mac OS not having some SSL certificate support. If I could get the ‘trusted site’ command into Thonny’s output, I believe I could make it work.

User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

Re: numpy

Sun Jan 24, 2021 9:40 am

I’ve found some helpful info here which says that it’s not the SSL certificate that’s a problem, but attempting to load C/C++ packages, not MicroPython. Not sure about this, but will continue investigating.

https://github.com/thonny/thonny/issues/1330

hippy
Posts: 9196
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: numpy

Sun Jan 24, 2021 12:08 pm

tony1tf wrote:
Sat Jan 23, 2021 11:57 pm
That installed numpy for the Mac, but not where Thonny could pick it up for programming the Pico. The trouble is I don't understand the structure of all this, so I am typing in the dark.
The package system for MicroPython is quite different to the package system for Python, especially when it comes to C extension packagess. Using "pip" to install a Python package isn't enough to make that available for MicroPython.

I expect this 'MicroPython isn't Python' is going to catch a few people out and especially when it comes to packages.

User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

Re: numpy

Sun Jan 24, 2021 12:09 pm

OK - answer found - numpy can't be installed on MicroPython devices:

https://github.com/thonny/thonny/issues ... -766325151

User avatar
scruss
Posts: 3842
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: numpy

Sun Jan 24, 2021 3:10 pm

numpy can't — it's meant for real computers with actual memory — but ulab can. It may need to be compiled into the MicroPython image, and it might be too big for the Raspberry Pi Pico anyway, but it provides a numpy-like vector maths interface.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

User avatar
tony1tf
Posts: 90
Joined: Tue Jul 03, 2012 12:33 pm

Re: numpy

Sun Jan 24, 2021 4:21 pm

Hi scruss

Thanks for that. Perhaps someone with more knowledge than me will port https://github.com/v923z/micropython-ulab to the Pico.

Tony

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 345
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: numpy

Sun Jan 24, 2021 7:58 pm

numpy can't — it's meant for real computers with actual memory — but ulab can. It may need to be compiled into the MicroPython image, and it might be too big for the Raspberry Pi Pico anyway, but it provides a numpy-like vector maths interface.
That was what I was referring to above
kilograham wrote:
Sun Jan 24, 2021 12:25 am
Someone was asking how to add a native C implemented python module to the RP2040 version of MicroPython, so I started this branch

https://github.com/raspberrypi/micropyt ... ed0a95a258

The example I used (in the comments) ulab I believe include numpy

So if you're feeling adventurous you can build that!
Basically the commit message suggests how to build ulab into the RP2040 version of micropython (which was what I tried) - it seemed happy enough with the two line test program I tried!

v923z
Posts: 1
Joined: Mon Jan 25, 2021 7:00 am

Re: numpy

Mon Jan 25, 2021 7:14 am

Hi all,

A friend of mine brought this discussion to my attention. I am the maintainer of ulab, and just wanted to point out that, if you need hooks, or middleware in ulab itself, I am more than happy to add that. I have accommodated similar requests from circuitpython and openmv in the past, and on those platforms, ulab is a one-stop solution: they simply link to my repository, and automatically compile from that code. Just let me know, if you need anything like that.

tannewt
Posts: 37
Joined: Tue Nov 17, 2020 1:14 am

Re: numpy

Tue Jan 26, 2021 12:26 am

`ulab` is enabled in the CircuitPython build for the Pico available here: https://circuitpython.org/board/raspberry_pi_pico/

CircuitPython getting started instructions are here: https://learn.adafruit.com/getting-star ... cuitpython

Basic API examples are here: https://learn.adafruit.com/circuitpython-essentials/

Return to “MicroPython”