Showing posts with label buildout. Show all posts
Showing posts with label buildout. Show all posts

Friday, December 23, 2016

My Python Workflow

This is basically what I did whenever starting on new Python project.

mkdir project_name
cd project_name
wget https://bootstrap.pypa.io/bootstrap-buildout.py
vim buildout.cfg

Where my buildout.cfg look like:-

[buildout]
parts = main

[main]
recipe = zc.recipe.egg
eggs =
    python-telegram-bot

interpreter = python


Then I just execute the following to get my new python environment initialize:-

python bootstrap.py
./bin/buildout

A python interpreter that already has access to my packages dependencies - in this case python-telegram-bot is ready in ./bin/python.

I'm a fan of buildout and shall write more about it in later post.

Thursday, September 10, 2009

Buildout custom Python interpreter

Menggunakan Buildout, kita boleh generate custom Python interpreter khusus untuk kegunaan projek buildout ini dengan sys.path disetkan kepada eggs dalam projek ini. Berikut contoh buildout.cfg yang digunakan:-


[buildout]
newest = false
parts = pylons python
find-links = http://pylonshq.com/download/0.9.7
develop = .

[python]
recipe = zc.recipe.egg
interpreter = python

[pylons]
recipe = zc.recipe.egg
eggs =
nose>=0.11.1
Paste>=1.7.2
PasteScript>=1.7.3
PasteDeploy>=1.3.3
Pylons==0.9.7
SQLAlchemy==0.5.5
Jinja2==2.1.1


Tapi apabila run, dapat error:-


We have no distributions for python that satisfies 'python'.
Getting distribution for 'python'.
We have a develop egg: setuptools 0.6c9
Running easy_install:
/usr/bin/python "-c" "from setuptools.command.easy_install import main; main()" "-mUNxd" "/home/kamal/webapps/clinic-pylons/eggs/tmpflXKv-" "-q" "/usr/lib/python2.5/lib-dynload"
path=/usr/lib/python2.5/site-packages

error: Couldn't find a setup script in /usr/lib/python2.5/lib-dynload
An error occured when trying to install Python 2.5.2.Look above this message for any errors thatwere output by easy_install.
While:
Installing python.
Getting distribution for 'python'.
Error: Couldn't install: Python 2.5.2


Yang buat aku bengang adalah sebelum ini tidak apa-apa masalah, menggunakan komputer yang sama. Puas Google tapi tak jumpa sebarang penyelesaian. Nampak macam aku sorang je ada masalah ini.

Hari ini, bila tengok balik buildout.cfg tersebut dan bandingkan error message yang keluar, baru aku nampak kesilapannya.


[buildout]
parts = pylons python

[python]
recipe = zc.recipe.egg
interpreter = python


Deklarasi di atas bermaksud untuk install Python, bukannya generate custom interpreter untuk projek aku. Buildout rupanya, bila kita tak nyatakan egg yang hendak di'install', akan cuba download egg dengan nama 'part-name' yang mana dalam kes ini adalah Python.

Deklarasi yang betul adalah:-


[buildout]
newest = false
parts = pylons
find-links = http://pylonshq.com/download/0.9.7
develop = .

[pylons]
recipe = zc.recipe.egg
interpreter = python
eggs =
nose>=0.11.1
Paste>=1.7.2
PasteScript>=1.7.3
PasteDeploy>=1.3.3
Pylons==0.9.7
SQLAlchemy==0.5.5
Jinja2==2.1.1


Masukkan je option untuk interpreter dalam part 'pylons', tak perlu kepada part yang khusus untuk install interpreter.