Out-of-memory when installing python package

My OpenWrt device has 128 MB of memory. When installing a Python package over pip3, the device returns with an out-of-memory error:

ERROR: Could not install packages due to an EnvironmentError: [Errno 28] No space left on device

I can confirm we run out of memory mid-install from monitoring the usage. So I decided to create a temporary swap file:

$ dd if=/dev/zero of=/swapfile bs=1024 count=524288`
$ mkswap /swapfile
$ chown root:root /swapfile
$ chmod 0600 /swapfile
$ swapon /swapfile

This works without error (the kernel supports swap files as per our make menuconfig).

The next time we try to install the package, we see our swap memory is being used:

              total        used        free      shared  buff/cache   available
Mem:         124864       17060       98780        1192        9024       78860
Swap:        524284       13056      511228

However right as the swap space starts to fill the error pops up again on install.

Also here is what shows with df:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 4352      4352         0 100% /rom
tmpfs                    62432     12916     49516  21% /tmp
/dev/mmcblk0          15248300    619224  13834788   4% /overlay
overlayfs:/overlay    15248300    619224  13834788   4% /
tmpfs                      512         0       512   0% /dev

Also have tried installing the package with --no-cache-dir flag without success.

I think /tmp reaches 100% at the time of the error. Is there a way to expand this?

Any ideas?