Workflow using virtualenv and pip
I have python2.6 and django1.2.3 already installed on my system (Ubuntu 10.x).
This is the setup i use for most of my projects. But for some projects I need sandboxed environments, different django version, some extra python modules and sometimes even different python version.So, I am tryin开发者_开发问答g to use pip and virtualenv now,but I am unable to change python and django version. Will I have to remove default setup and move all existing projects into 1 virtualenv. Can I avoid this? Even if I do that, how can I specify a different version of python?
If I have to remove the old settings. How do i do that? I have currently most of the things installed in /usr/local/lib/python2.6/dist-packages/
but I am not sure if there is anything installed anywhere else also.
If I have a completely blank setup with just Ubuntu, what is the ideal workflow? Is it this one?
Install python
$ sudo apt-get install python-setuptools
$ sudo apt-get install python-virtualenv
$ sudo easy_install pip
$ sudo pip install virtualenvwrapper
You want to do:
virtualenv --python=/path/to/python/version --no-site-packages ENV_NAME
For example:
virtualenv --python=/usr/bin/python2.6 --no-site-packages my_project_env
If you follow this for your projects you should be able to have a separate configuration for each one.
I have installed every Python verison I need (which is 2.4, 2.5, 2.6, 2.7, 3.1 and also 3.2) from source. That's always the best thing to do, so you don't mess up the system Python.
I installed them in /opt. Like so (you need a bunch of Ubuntu packages too, first):
./configure --prefix /opt/pythonxx
make -j2; make install # j2 is a nice trick there for dualcores not everyone knows.
Then I for each version install the things I need. I start with installing Distribute:
wget http://nightly.ziade.org/distribute_setup.py
/opt/pythonxx/bin/python distribute_setup.py
(Except for Python 3, who needs distribute_setup3.py) Then I can install pip
/opt/pythonxx/bin/easy_install pip
And virtualenv:
/opt/pythonxx/bin/pip install virtualenv
(Virtualenv3 or virtualenv5 for Python 3)
And that's it! If I want to make a virtualenv using Python 2.4, I do:
/opt/python24/bin/virtualenv foobar
And Python 2.7:
/opt/python27/bin/virtualenv foobar
Running python is just
/opt/python24/bin/python
Etc. I never install anything in the above Pythons except these modules, and PIL (because PIL is a pain, but now there is Pillow, so you don't have to do that either). I use zc.buildout and virtualenv to keep the pythons clean.
You can use virtualenv --no-site-packages ENVNAME
and that will make sure the default Django in your system Python won't be included in your new environment.
For different versions of Python, you can follow these instructions from a superuser.com post.
精彩评论