WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Python Library Module persistence  (Read 2077 times)

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Python Library Module persistence
« on: February 27, 2020, 01:43:15 AM »

Python relay board installation is successful, but not persistent (does not survive reboot).  The installation file (setup.py) published on Github

INSTALLATION:

Code: [Select]
tc@box:~/megaio-rpi/python/megaio$ sudo -H python setup.py installrunning install
running bdist_egg
running egg_info
writing megaio.egg-info/PKG-INFO
writing top-level names to megaio.egg-info/top_level.txt
writing dependency_links to megaio.egg-info/dependency_links.txt
reading manifest file 'megaio.egg-info/SOURCES.txt'
writing manifest file 'megaio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv6l/egg
running install_lib
running build_py
creating build/bdist.linux-armv6l/egg
creating build/bdist.linux-armv6l/egg/megaio
copying build/lib/megaio/__init__.py -> build/bdist.linux-armv6l/egg/megaio
byte-compiling build/bdist.linux-armv6l/egg/megaio/__init__.py to __init__.pyc
creating build/bdist.linux-armv6l/egg/EGG-INFO
copying megaio.egg-info/PKG-INFO -> build/bdist.linux-armv6l/egg/EGG-INFO
copying megaio.egg-info/SOURCES.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
copying megaio.egg-info/dependency_links.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
copying megaio.egg-info/top_level.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/megaio-1.3.1-py2.7.egg' and adding 'build/bdist.linux-armv6l/egg' to it
removing 'build/bdist.linux-armv6l/egg' (and everything under it)
Processing megaio-1.3.1-py2.7.egg
Removing /usr/local/lib/python2.7/site-packages/megaio-1.3.1-py2.7.egg
Copying megaio-1.3.1-py2.7.egg to /usr/local/lib/python2.7/site-packages
Adding megaio 1.3.1 to easy-install.pth file

Installed /usr/local/lib/python2.7/site-packages/megaio-1.3.1-py2.7.egg
Processing dependencies for megaio==1.3.1
Finished processing dependencies for megaio==1.3.1

INSTALLATION TEST


Code: [Select]
tc@box:~/megaio-rpi/python/megaio$ sudo pythonPython 2.7.13 (default, Dec 23 2016, 18:28:09)
[GCC 6.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import megaio
>>> megaio
<module 'megaio' from 'megaio/__init__.pyc'>
>>>

QUESTION
What is the process to make python installs persistent?

Code: [Select]
tc@box:~$ sudo python
Python 2.7.13 (default, Dec 23 2016, 18:28:09)
[GCC 6.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import megaio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named megaio
Raspberry Pi Zero W

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python Library Module persistence
« Reply #1 on: February 27, 2020, 02:36:01 AM »
It would be easier (and use less ram) to make extensions out of the various python packages, no?

..something like:
Code: [Select]
$ tce-load -i compiletc python3.6-dev

$ cd package_name

$ python3.6 setup.py build
$ sudo python3.6 setup.py install --root=/tmp/pkg

..then delete the pycache folders and *pyc/*pyo files under /tmp/pkg/usr/local and finally:
Code: [Select]
$ cd /tmp
$ sudo mksquashfs pkg/ py_package_name.tcz
« Last Edit: February 27, 2020, 07:24:50 AM by Juanito »

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Re: Python Library Module persistence
« Reply #2 on: March 01, 2020, 02:44:50 PM »
@juanito:  is there a list of good references for making .tcz packages?  I would appreciate a recommended reading list and examples from you.  Thanks
Raspberry Pi Zero W

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python Library Module persistence
« Reply #3 on: March 02, 2020, 12:05:53 AM »
@juanito:  is there a list of good references for making .tcz packages?  I would appreciate a recommended reading list and examples from you.
You can take a look here: http://wiki.tinycorelinux.net/wiki:creating_extensions?

.otherwise, this would work in many cases for python packages:
Code: [Select]
$ tce-load -i compiletc squashfs-tools python3.6-dev

$ tar xf smbus2-0.3.0.tar.gz
$ cd smbus2

$ python3.6 setup.py build
$ mkdir /tmp/pkg
$ sudo python3.6 setup.py install --root=/tmp/pkg

[remove pycache folders and *.pyc *.pyo files under /tmp/pkg/usr/local]

$ cd /tmp
$ sudo mksquashfs pkg/ python3.6-smbus2.tcz
$ sudo chown tc:staff python3.6-smbus2.tcz
$ md5sum python3.6-smbus2.tcz > python3.6-smbus2.tcz.md5.txt
$ unsquashfs -ll -d '' python3.6-smbus2.tcz | grep -v '^d' | sed -e 's#.* /#/#' -e 's# -> .*##' -e 1,3d > python3.6-smbus2.tcz.list