1

I want to replace the default CPython (Python) with pypy (1.8).

Will this cause a problem? (I ask because python seems to be an important component in Ubuntu.).

I've built pypy and have installed it on a virtual machine of Ubuntu (I'm testing this idea out before I do it to my actual machine. So while we can try thing my intention is to accomplish this in "real life" as it were.).

Pypy is usable from the anywhere in the system via pypy as opposed to python.

pypy my_python_script.py

It seems to be installed fine and seems usable.

Now, I want to make it so that any time I want to use python, it'll assume I mean pypy.

For example, I installed Django in to pypy but when I try to run django-admin.py it has no idea what I'm talking about. I imagine I could accomplish this part by adding wherever django-admin.py is to my $HOME variable.

That, for now, is aside the point.

So, my question is how do I replace standard python with my own preferred version -- in this case, pypy.


I'm revising my question based on the answer thus far -- that replacing CPython in whole is not a good idea as it could foobar the system.

I've read a bit on virtualenv -- looks good but it doesn't seem to answer my question (or, I'm missing how).

I want to use pypy for my work in python. Development work for things like, Django, Google App Engine and other such nonsense. (I realize there could be a compatibility issue, I'll address those with unit tests or some other means. Just know, it's beside the point at the moment.)

So, keeping this in mind, say I want to use pypy instead of python. And for ./django-admin.py to work globally, it'd have to be installed with the system's python. How might I configure the system to support these "global" python scripts from either pypy or the main system python?

1
  • could some one add a pypy tag to this, please. I could not 'create' the tag.
    – Frank V
    Feb 12, 2012 at 1:00

1 Answer 1

4

It is not a good idea to mess with system python because, as you have noticed, Ubuntu uses python widely so any change may render your system unstable.

Moreover, as a developer, I can tell you that globally installing third-party libraries into your system Python is not a good idea either - everything will start falling apart as soon as you have two projects which require different versions of Django, for example.

Luckily, Python has very good tools for creating isolated environments which may be completely independent from the system Python.

Have a look at virtualenv and zc.buildout (along with djangorecipe) for a civilized solution to your problem. :)

UPDATE: Very briefly, here's how zc.buildout would solve your problem:

You create a directory where you put bootstrap.py and buildout.cfg file which contains

[buildout]
parts = django
versions = versions

[versions]
django = 1.2.5

[django]
recipe = djangorecipe
settings = development
eggs = ${buildout:eggs}
project = mymegaapp

Then you run /path/to/python/interpreter/python bootstrap.py, at which point your buildout "remembers" which python interpreter you used. It also creates a bin directory where all your "global" scripts will be auto-generated. Then you run bin/buildout, which downloads and installs Django of specified version, creates an empty project called "mymegaapp" etc. After it's finished, you'll find django command in the bin directory which is equivalent to django-admin.py, so you can run

bin/django syncdb
bin/django runserver

etc. You never have to worry to remember to use the correct interpreter. Of course, this is just a very small part of what you can do with buildout... just think about putting buildout.cfg into a VCS so you can re-build the application with all the dependencies at exact versions, even in a few years from now... or about having multiple configs for different "deployment configurations" :)

For a quick example how to do this with virtualenv you can have a look at this article - the instructions should work apart from the very first part - you'll need to install setuptools with your pypy, not with the 'standard' interpreter. Then you'll use python script generated in your sandbox's bin directory:

cd myapp
../venv/bin/python manage.py runserver 0.0.0.0:8000

(I have a feeling the question becomes less and less relevant to Ubuntu... should we ask for it to be migrated to stackoverflow?)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .