金子邦彦研究室インストールUbuntu の種々のソフトウェア(インストール)ZDOB のインストールと Python プログラム例(Ubuntu 上)

ZDOB のインストールと Python プログラム例(Ubuntu 上)

ZODB はオブジェクトデータベース管理システム

前準備

Ubuntu のシステム更新

UbuntuUbuntu で OS のシステム更新を行うときは, 端末で,次のコマンドを実行する.

UbuntuUbuntu のインストールは別ページ »で説明

sudo apt -y update
sudo apt -yV upgrade
sudo /sbin/shutdown -r now

Python3 開発用ファイル,pip, setuptools, venv のインストール(Ubuntu 上)

Python のインストールは行わない(Ubuntu のシステム Python を用いる.)

Python, pip のコマンドでの起動のまとめ.

Ubuntu のシステム Python を用いるとき, python, pip は,次のコマンドで起動できる.

Ubuntu での Python 開発環境(JupyterLab, spyder, nteract)のインストール: 別ページ »で説明している.

Python3 開発用ファイル,pip, setuptools, venv のインストール

端末で,次のコマンドを実行する.

sudo apt -y update
sudo apt -y install python-is-python3 python3-dev python-dev-is-python3 python3-pip python3-setuptools python3-venv build-essential

ZODB のインストール

端末で,次のコマンドを実行する.

sudo pip3 install zodb

ZODB のプログラムを動かしてみる

http://www.zodb.org/en/latest/documentation/tutorial.html (現存しない) に記載されていた account.py を使っている.

import persistent
import ZODB, ZODB.FileStorage, ZODB.DB 
import BTrees.OOBTree

class Account(persistent.Persistent):
    def __init__(self):
        self.balance = 0.0
    def deposit(self, amount):
        self.balance += amount
    def cash(self, amount):
        assert amount < self.balance
        self.balance -= amount

storage = ZODB.FileStorage.FileStorage('mydata.fs')
db = ZODB.DB(storage)
connection = db.open()
root = connection.root

# create one object
root.accounts = BTrees.OOBTree.BTree()
root.accounts['account-1'] = Account()
root.accounts['account-1'].balance

[image]