Python virtualenv quickstart with Django
One of the solutions to the ghetto of Python package management is to use a sand-boxed Python install like virtualenv. This is the very same technique we use at Smarkets to simultaneously run Pylons and Django alongside each other on a single server.
This post is briefly about how to get up and running in a few minutes using virtualenv and Django.
Install virtualenv
Installing virtualenv is easy on a Linux or Mac system, but the instructions that follow are Linux (Ubuntu, actually) specific. First you’ll need setuptools:
sudo apt-get install python-setuptools
Then we can easy_install virtualenv:
sudo easy_install virtualenv
We need to use sudo here because it has to install to a global location. Don’t worry, this is the last time we’ll need to do something as root.
Create your virtualenv
cd to wherever it is you keep your projects (for me, in ~/src), and run:
virtualenv --no-site-packages venv
In this instance I’ve chosen venv as the name for my virtual environment. The —no-site-packages command tells virtualenv not to symlink the global site packages into my local environment, just take the Python standard library. This is important, because it helps us avoid the dependency difficulties mentioned above.
At this stage you might want to add venv to your list of ignored files, as you don’t want it to be committed to source control:
echo "venv" >> .gitignore
Installing Django
Now, the trick with virtualenv is that it creates its own Python and easy_install binaries, which means you can install/run things specifically in your environment. Let’s install Django:
./venv/bin/easy_install django
And it’s done. easy. You might also want to install the MySQL bindings and IPython for ease of use:
./venv/bin/easy_install ipython python-mysql
To start a new Django project, you’ll note that a django-admin.py file will have been installed for you in the environment:
./venv/bin/django-admin.py startproject myapp
Obviously you can skip this step if you have an existing Django project.
Running Django
Now the last step, which is probably obvious by now, is to run Django’s runserver with the virtual Python binary:
cd myapp ../venv/bin/python manage.py runserver 0.0.0.0:8000
And you’re away!
Closing
Just make sure whenever you need to add another package that you install it in the virtualenv, and not in the global packages directory. If you want to deploy using virtualenv, here are some instructions for using mod_wsgi with virtualenvs.
Post Notes
-
graphiste-moins-cher likes this
-
graphiste-pas-cher likes this
-
beat-making-software-1 likes this
-
natural-dog-food-1 likes this
-
supraveghere--video likes this
-
cartouches-imprimante likes this
-
recharge-imprimante likes this
-
parfums-pour-femmes likes this
-
parfums-moins-cher likes this
-
sos-serrurier likes this
-
serrurier-sur-paris likes this
-
appliances-repair-san-francisco likes this
-
appliance-repair-1 likes this
-
camere-de-supraveghere likes this
-
camere-supraveghere likes this
-
mulheres-gostosas-bundas likes this
-
videos-muito-engracados likes this
-
bundas--lindas likes this
-
mulheres-gostosas-de-biquini likes this
-
job-application likes this
-
seo-agency-australia likes this
-
search-engine-experts likes this
-
seo-trends-2013 likes this
-
sydney-marketing-agency likes this
-
web-developments-australia likes this
-
australian-hotel-suppliers likes this
-
restaurant-products-australia likes this
-
bulk-hotel-products likes this
-
wholesale-restaurant-supplies likes this
-
punk-apparel likes this
-
goth--clothing likes this
-
pasfoto-maken-groningen likes this
-
pasfoto-groningen likes this
-
cialis-1 likes this
-
viagra-1 likes this
-
boxer-puppies likes this
-
home-loan-1 likes this
-
mortgage-1 likes this
-
richfenne likes this
-
booster-trafic-site-com likes this
-
hairstore likes this
-
agence-web-2 likes this
-
annonces-gratuite likes this
-
freez-1 likes this
-
wakineo likes this
-
eurinfor likes this
-
l-oreal-professionnel likes this
-
r4i--3ds likes this
- Show more notes