| Easily install all Python versions under Linux and OSX using collective.buildout.pythonPosted on July 16, 2010 by Mikko OhtamaaFiled Under plone, python, technology, ubuntu Here are short instructions how to install all versions (2.4, 2.5, 2.6, 2.7 and 3.1) of Python interpreters on UNIX system. The instructions were tested on Ubuntu 10.04 Lucid Lynx Linux but should work on other systems as is. The installation is based of downloading, compiling and installing different Pythons and their libraries using buildout tool. A buildout configuration for doing this is maintained by a Plone community. This buildout is especially useful to get Python 2.4 properly running under the latest Ubuntu 10.04 Lucid Lynx. This is because Ubuntu repositories won’t ship with Python 2.4 packages anymore. The installation will also include static compilation of some very popular libraries. These are dependencies for other Python packages including, but not limited, to
Prerequisites
Running itsvn co http://svn.plone.org/svn/collective/buildout/python/ cd python python bootstrap.py bin/buildout Using itAll Pythons are under virtualenv installations. This means that you can activate one Python configuration for your shell once easily (python command will run under different Python versions). Activating Python 2.4 source python/python-2.4/bin/activate (python-2.4)moo@murskaamo:~/code$ python -V Python 2.4.6 Check that Python Imaging Library works python Python 2.4.6 (#1, Jul 16 2010, 10:31:46) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import PIL (No exceptions raised, Python Imaging Library works well).
Using paster local commands with buildout and avoiding the infamous dependency issuePosted on April 13, 2010 by Mikko OhtamaaFiled Under plone, python, technology IntroductionPaste script is a part of Python Paste web development utilities. Its paster create command is used by various Python frameworks to generate skeleton code for a development project. Paster and local commandsBesides generic project templates, paster provides local commands which are project aware commands to add more modules into an existing project. Local commands are made available by paster extensions. For example, ZopeSkel product has various local commands to generate skeletons into Plone/Zope projects automatically
… and so on. For example, you could generate a project template for Plone add-on module and then create content types there using a local paster command. The local commands become available when you execute paster command in the folder of your project. Example: paster create -t archetype myorg.customploneaddon cd src/myorg.customploneaddon # Now new paster commands are available paster Usage: ../../bin/paster COMMAND usage: paster [paster_options] COMMAND [command_options] ... Commands: ... ZopeSkel local commands: addcontent Adds plone content types to your project Above, ZopeSkel paster template adds its addcontent templates. Now you can use addcontent local command to contribute to the existing project paster addcontent -t contenttype MyShinyWebPage ZopeSkelFor more information how to use paster to create add-ons and add-on submodules for Plone, see here. To see list of available paster local commands, run paster command ../../bin/paster addcontent --list … in your development project. For ZopeSkel specific projects the output should be something like this: Available templates:
atschema: A handy AT schema builder
contenttype: A content type skeleton
form: A form skeleton
How paster local commands workpaster reads (evaluates) setup.py file which declares a Python egg. If it founds paster_plugins section there, it will look for local commands there. For example, Plone project templates declare the following paste_plugins in setup.py: paster_plugins = ["ZopeSkel"] setup.py install_requiresPython modules can dependencies to other modules using setup.py and install_requires section. For example, a Plone add-on might read: install_requires=['setuptools',
# -*- Extra requirements: -*-
"five.grok",
"plone.directives.form"
],
This means that when you use setuptools/buildout/pip/whatever Python package installation tool to install a package from Python Package Index (PyPi) it will also automatically install dependency packages declared in install_requires. paster and install_requiresThis is where things usually go haywire. Let’s assume you are using paster in a project which contains N python packages. You probably use an external configuration system to manage your installed applications and their versions to make repeatable deployments possible (hint: buildout is gaining traction in Python community lately). Paster is not aware of this external Python package configuration set (paster cannot see them in its PYTHONPATH). So what happens when you try to execute paster create which reads setup.py containing install_requires and encounters dependencies? Paster will try automatically download and install them locally in that folder. Plone and Zope ecosystem contains over hundreds of reusable components, in nice dependency hierarchy. paster create would try to pull all them in to your source tree as *.egg folders. See discussion here. WarningDo not never use system paster command. Do not ever run sudo easy_install ZopeSkel. Do not ever run paster local commands using a paster command from your system-wide Python installation. WarningThe internet is full of tutorial saying easy_install ZopeSkel. If you ever encounter this kind of tutorial, it’s wrong. Paste and buildoutIf you are using buildout to manage your Python application deployment, you can integrate paster nicely with it. Add to your buildout.cfg: parts =
...
paster
[paster]
recipe = zc.recipe.egg
eggs =
PasteScript
ZopeSkel
${instance:eggs}
After rerunning buildout, buildout adds paster command to bin folder. Then you can run paster from buildout folder: bin/paster … or in a buildout managed project under src folder… ../../bin/paster This way paster is aware of your deployment configuration and local commands won’t explode on your face anymore. Thanks Martin Aspeli to helping with how buildout + paster should be done.
Installing Python Imaging Library (PIL) under virtualenv or buildoutPosted on November 19, 2009 by Mikko OhtamaaFiled Under plone, python, technology I have greatly struggled to have PIL library support in isolated Python environments like virtualenv –no-site-packages. For example, when installing Satchmo shop under virtualenv:
Though it clearly is there, installed by easy_install PIL command: ls ../lib/python2.5/site-packages/PIL-1.1.7-py2.5-linux-x86_64.egg ArgImagePlugin.py ExifTags.py GimpGradientFile.pyc... Does anyone know if this problem is with PIL itself, eggified PIL or something else? In any case, there is an easy workaround: use system-wide PIL (sudo apt-get install python-imaging) and symlink PIL from your site-wide installation under the isolated Python environment: (satchmo-py25)mulli% pwd /srv/plone/mmaspecial/satchmo-py25/lib/python2.5/site-packages (satchmo-py25)mulli% ln -s /usr/lib/python2.4/PIL . That works for now, but I’d like to learn how to make virtualenv and buildout install PIL egg bullet-proof way.
Mysterious buildout error – missing docs/HISTORY.txt filePosted on October 1, 2008 by Mikko OhtamaaFiled Under Plone (old), python I was getting the following error with Plone buildout … Develop: '/home/moo/workspace/collective.easytemplate'
Traceback (most recent call last):
File "/tmp/tmp_G8621", line 11, in ?
File "/usr/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 655, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 931, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 919, in run_setup
run_setup(setup_script, args)
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 26, in run_setup
DirectorySandbox(setup_dir).run(
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 63, in run
return func()
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 29, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 9, in ?
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 166, in _open
return _open(path,mode,*args,**kw)
IOError: [Errno 2] No such file or directory: 'docs/HISTORY.txt'
An internal error occured due to a bug in either zc.buildout or in a
recipe being used:
Traceback (most recent call last):
File "/home/moo/workspace/Plone-3.1/eggs/zc.buildout-1.1.1-py2.4.egg/zc/buildout/buildout.py", line 1477, in main
getattr(buildout, command)(args)
File "/home/moo/workspace/Plone-3.1/eggs/zc.buildout-1.1.1-py2.4.egg/zc/buildout/buildout.py", line 324, in install
installed_develop_eggs = self._develop()
File "/home/moo/workspace/Plone-3.1/eggs/zc.buildout-1.1.1-py2.4.egg/zc/buildout/buildout.py", line 556, in _develop
zc.buildout.easy_install.develop(setup, dest)
File "/home/moo/workspace/Plone-3.1/eggs/zc.buildout-1.1.1-py2.4.egg/zc/buildout/easy_install.py", line 868, in develop
assert os.spawnl(os.P_WAIT, executable, _safe_arg (executable), *args) == 0
AssertionError
My product had docs folder. HISTORY.txt was there properly. This made me scratch my head for a while. Buildout calls easy_install as an external process. If easy_install eggs have dependencies in their setup.py easy_install tries to download and install these eggs. There is no reported progress what eggs are installed in easy_install process created from buildout. Looks like buildout verbosity (-v) switch does not reach easy_install. So the problem was not in my product, but in its dependency. However the debug output did not reveal that we were dealing with a dependency. Is there easy means to solve this kind of problems? I bluntly put debug prints inside my server wide setuptools Python files to known which was the faulty dependency. It turned out that easy_install was trying to execute setup.py against a downloaded source distribution (.tar.gz). I had the same egg as a local source code copy. The source code contains docs folder, the egg doesn’t. The solution was to change buildout.cfg develop directive to be the same as the flattened dependency order of the eggs (dependencies come top). This way setup.py was evaluated correctly against the source code folder. Python code management & deployment – a glance at zc.buildout and few othersPosted on September 2, 2008 by Tuukka MustonenFiled Under development tools, django, python, zope We’ve been using zc.buildout for Plone deployment and it’s working out great. A few days ago implemented a buildout recipe for Django project deployment, automatic web configuration, symlinking, media-folder structuring etc. and while I got it working, I came up with twisted feelings. Buildout is from the creators of Zope (I suppose) so you can expect a powerful project code management tool. The question is, however, whether or not it suits your needs. In my case I found out it too heavy. I mean, to add even a simple task you have to create a new “recipe” (a package) that does the tricks. Of course some recipes are generic (found from PyPi) and you can just run them with your own INI options, but in my case I had to do some custom implementation. Creating a new python package isn’t that hard for sure I found out that zc.buildout has some nice features like:
The problems?
There’s no denying zc.buildout is powerful, but I wouldn’t use it for projects which need reasonable amount of customization. It’s just plain easier and quicker to write shell scripts and while those won’t provide you with any sort of ready tools you won’t propably need them. For bringing up somewhat static environment, where you don’t need to hack things (like that for Plone) it’s quite a decent option, however. I also explored alternatives to zc.buildout. I’ve been reading about earlier virtualenv but haven’t really tried it out until now. It looks very promising and creates a more flexible environment compared to zc.buildout. Of course their goals are not exactly the same. Also, there are a few other alternatives out there, among them a new Python code management tool called Paver (just look at that cool logo.. it does remind you of Indiana Jones, does it not?). I glanced through the Paver docs and it looks like it might be the way to go (Paver also supports virtualenv), but didn’t quite get the grasp of the benefits just yet. Anyway, if you are still interested in code management and deployment, I’d recommend you to read the Paver release announcement and also Paver forewords. They should clear things up. |
