Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, March 28, 2015

How to upgrade Django 1.6 to Django 1.7

  • Update django package:

    pip install -U Django
    
  • Remove 'south' from INSTALLED_APPS.
  • Delete all your (numbered) migration files, but not the directory or init.py - make sure you remove the .pyc files too.
  • Run python manage.py makemigrations. Django should see the empty migration directories and make new initial migrations in the new format.
  • Run python manage.py migrate. Django will see that the tables for the initial migrations already exist and mark them as applied without running them. (Only matching table names are checked; not their full schema
  • it’s up to you to make sure the existing schema is up to date with your models!)
  • Uninstall south package:

    pip uninstall south
    
  • Update requirements.txt file:

    pip freeze > requirements.txt
    

Webfaction

I'm using a great Python hosting - Webfaction. So here is short notes how to upgrade existing deployed application to Django 1.7.

  • Create new application with Django 1.7
  • Copy project folder from old Django 1.6 application to new Django 1.7 application.
  • Modify httpd.conf accordingly with new folder structure.
  • Stop existing existing application with django 1.6.
  • Restart new django 1.7 application:

    ~/webapps/django_17/apache2/bin/restart
    
  • Remove django 1.6 from Websites-> yourdomain.com -> Contents.
  • Add new django 1.7 app to Websites-> yourdomain.com -> Contents.

Done. Check how it works.

PS: And don't forgot to update fabric deployment file accordingly.

Saturday, May 5, 2012

Python development environment for Ubuntu 12.04 Precise

Frankly, my upgrade for the newest release of Ubuntu 12.04 Precise broke my OS. And I didn't have any chance to recover it. So I just reinstalled Ubuntu and got fresh, but empty operation system. The last time when I did setup of Python development environment was one year ago. All my notes about this things were old and unsuitable for the latest Ubuntu release. This post is summary of my actions to setup Python development environment from scratch.
Install Python setuptools package:
sudo apt-get install python-setuptools python-pip
Install virtualenvwrapper:
sudo pip install virtualenvwrapper
Setup virtualenvwrapper:
mkdir -p ~/.virtualenvs
echo 'export WORKON_HOME=~/.virtualenvs' >> ~/.bashrc
echo 'export DJANGO_SITES_ROOT=$HOME/projects/' >> ~/.bashrc
echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bashrc
source ~/.bashrc
Install Django extension for virtualenvwrapper. I have several Django projects, but if you aren't using Django, then you can skip this step:
sudo apt-get install git-core
mkdir -p ~/.virtualenvs/django-libs
cd ~/.virtualenvs/django-libs
git clone https://github.com/epicserve/django-environment.git
cd ~/.virtualenvs/django-libs/django-environment/django_env/bin/
install.py
Test virtualenvwrapper:
cd ~/projects
mkvirtualenv example
cd example && ls
Install PIL with JPEG, ZLib and FreeType support, if you aren't using PIL, then you can skip this step:
sudo apt-get install libjpeg62-dev zlib1g-dev libfreetype6-dev
cd ~/.virtualenvs/{project-name}
For 32-bit systems:
ln -s /usr/lib/i386-linux-gnu/libz.so ./lib/
ln -s /usr/lib/i386-linux-gnu/libjpeg.so ./lib/
ln -s /usr/lib/i386-linux-gnu/libfreetype.so ./lib/
For 64-bit systems:
ln -s /usr/lib/x86_64-linux-gnu/libz.so ./lib/
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so ./lib/
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so ./lib/

pip install PIL
I'm big fan of Vim, so here is steps for Vim also:
sudo apt-get install vim.gtk
Install Pathogen plugin:
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -so ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
add to ~/.vimrc file:
call pathogen#infect()
Install Fugitive for Git support and Python-mode for all Python stuff in Vim:
cd ~/.vim/bundle
git clone git://github.com/tpope/vim-fugitive.git
git clone git://github.com/klen/python-mode.git
Install super-fast Command-T plugin for opening files in Vim:
cd ~/.vim/bundle
git clone git://git.wincent.com/command-t.git
cd ~/.vim/bundle/command-t
rake make
That's all folks. I will keep this post updated for a while.
And If you have any comments and suggestions, please, post them in comments. Thanks.