buildout - using different python version
Asked Answered
G

3

7

i have set up buildout project (django to be specific) that has to run in old machine, it works fine in my local system with python 2.7.

In production server it runs python 2.5 and i want to configure buildout that it would download and use 2.6, but only this project not system wide.

So i assume it should use some sort of recipe, but witch and how? I cannot find one. I hope to achieve it only using buildout.cfg file..

Gemoets answered 20/4, 2011 at 6:21 Comment(0)
M
9

Buildout specifically supports this scenario. Each part in a buildout can use it's own python interpreter, or you can set one python interpreter globally for all parts. This defaults to the python used to run buildout.

To set the python interpreter used, set the python option to the name of a part that contains an executable option. This can be a part that builds a whole new python interpreter. Here is an example:

[buildout]
python = python
parts =
    python

[python]
recipe = zc.recipe.cmmi
url = http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
executable = ${buildout:directory}/parts/python/bin/python2.6
extra_options=
    --enable-unicode=ucs4
    --with-threads
    --with-readline

Any other parts in this buildout now will use the python 2.6 executable.

You may want to symlink the python script into the buildout bin/ directory as well; the following part would do that for you:

[pythonbin]
recipe = plone.recipe.command
command = ln -s ${python:executable} ${buildout:bin-directory}/python
Maneuver answered 20/4, 2011 at 7:42 Comment(2)
Sorry, but how it differs from my update? And how it helps me? it seems that i passed this part. Thanks for help!Gemoets
I wrote this answer before you edited your question. I cannot answer questions that are being rephrased, now, can I? ;-)Maneuver
A
4

Whichever python you use to do run the initial bootstrap.py is the one that will be used for your entire project. All paths will reference that specific python and the sitepackages for that specific python will be used.

This is one of the best things about buildout

This is a 32 bit python 2.6:

/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 boostrap.py

This is a 64 bit python 2.7:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python bootstrap.py

Now go look at the bin/ it created.

Then do your actual bin/buildout -c dev.cfg and look at the scripts in the bin. For my 32 bit example:

For the first one I see in my django file:

#!/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
...
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages',

The accepted answer says you need to compile a whole python. This is not needed nor advised, though it would mean you have a completely isolated sitepackages. But there are easier ways to tell buildout to not include the sitepackages.

The answer from esaelPsnoroMoN is actually correct, but s/he didn't describe the solution very well. (I ignored it myself before)

Albrecht answered 12/12, 2012 at 12:39 Comment(1)
What was "the answer from esaelPsnoroMoN"? It appears to be missing now...Scone
S
0

Answer of Martijn Pieters doesnt seem to help me. I need different versions of python inside buildout scripts. This is my example

[buildout]
parts = py2script
        py3script
index = https://pypi.python.org/simple

[python36]
executable = /usr/bin/python3.6
[python27]
executable = /usr/bin/python2.7

[py3script]
recipe = zc.recipe.egg:scripts
python = python36
eggs = bobo
interpreter = python3_interpreter

[py2script]
recipe = zc.recipe.egg:scripts
python = python27
eggs = bobo
interpreter = python2_interpreter

Every time inside python(2|3)_interpreter scripts will be written that python version which I used for bootstraping. So my buildout.cfg doesnt seem to work as expected.

Satyriasis answered 28/3, 2018 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.