试用一下PyPy



Luo Weifeng 2011-8-28

最近,Pypy一度吸引了Python社区的眼球, 因为在完全兼容的前提下能将python性能提高好几倍,而且更节省内存, 这无疑是pythoner的福音啊。  为了不影响系统中的一些东西,推荐在vitrualenv中做个测试。


老外这篇文章介绍了 比较安全的试用pypy的方法, 使用vitrualenv 。

http://ch0wn.posterous.com/pypy-15-with-virtualenv-on-ubuntu-natty


PyPy 1.5 with virtualenv on Ubuntu Natty
PyPy 1.5 was released yesterday supporting all features of CPython 2.6 and CPython 2.7. So if you’re still doing Python 2 development, there is no excuse for not using it from now on. I’m going to explain how to do that on Ubuntu Natty.
Installing PyPy
Currently, there are no offical Ubuntu packages available on their official PPA. However, using the binary downloads in combination with the latest release of virtualenv will give you a comfortable environment.


All you need to do, is download the 32 bit or 64 bit version depending on your architecture and extract them wherever you want. Personally, I prefer a folder in my home directory.


Upgrading Virtualenv
Virtualenv 1.6.1 added PyPy 1.5 support. I created a PPA with an updated package. Execute these commands to get it:


sudo apt-add-repository ppa:passy/python
sudo apt-get update
sudo apt-get install python-virtualenv
If everything went right, virtualenv --version should now print 1.6.


Note: My virtualenv build lacks a debian-specific patch that uses distribute instead of setuptools by default. To enable the debian behavior, you can set the VIRTUALENV_USE_DISTRIBUTE environment variable in your .bashrc or pass —distribute whenever you create a new virtualenv.


Creating a virtualenv
To use PyPy instead of CPython, all you need to do is provide a path to the PyPy executable when creating a new virtualenv. In my case, PyPy is installed at /home/pascal/Applications/pypy-1.5 so the full command is


virtualenv -p /home/pascal/Applications/pypy-1.5/bin/pypy venv
If you’re using virtualenvwrapper there is no need to worry. The Ubuntu version will continue to work with the updated version of virtualenv.


Running a test
To verify your installation, I’m going to create a bare-bone django project and start the development server with PyPy.


cd /tmp
virtualenv --distribute -p /home/pascal/Applications/pypy-1.5/bin/pypy djangove
source djangove/bin/activate
pip install django
django-admin.py startproject testproject
cd testproject
pypy manage.py runserver
Now open a browser, navigate to http://localhost:8000 and enjoy your PyPy-powered django test page.

你可能感兴趣的:(django,python,Debian,ubuntu,download,behavior)