Friday, January 17, 2014

Installing and using elastic search and python pyes, django... on Arch/Manjaro Linux

sudo pacman -S pip
sudo  pip install pyes
sudo pip install django

$ python
Python 3.3.2 (default, Sep  6 2013, 09:30:10)
[GCC 4.8.1 20130725 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.6.1
>>>


The Django tutorial needs version 1.7.

https://docs.djangoproject.com/en/dev/intro/tutorial01/

This tutorial is written for Django 1.7 and Python 3.2 or later. If the Django version doesn’t match, you can refer to the tutorial for your version of Django by using the version switcher at the bottom right corner of this page, or update Django to the newest version. If you are still using Python 2.7, you will need to adjust the code samples slightly, as described in comments.

 Lets install the Python IDE erric and try it out

> sudo pacman -S eric

https://wiki.archlinux.org/index.php/Django

Hmmm...lets not upgrade django and lets usethe 1.6 tutorial

https://docs.djangoproject.com/en/1.6/intro/tutorial01/

> python -c "import django; print(django.get_version())"
1.6.1

> sudo ln -s /usr/lib/python3.3/site-packages/django/bin/django-admin.py /usr/local/bin
> django-admin.py startproject mysite

> cd mysite
 
> python manage.py runserver
Let’s look at what startproject created:
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
 
 
> cd mysite
 
> python manage.py runserver
 
View the site in the browser at http://127.0.0.1:8000/ 

It worked!

Congratulations on your first Django-powered page.

Of course, you haven't actually done any work yet. Next, start your first app by running  python manage.py startapp [appname].
You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!
 
Now lets try to connect elasticsearch to django
 
http://haystacksearch.org/ 

> sudo pip install django-haystack

http://rise3d.blogspot.com/2013/08/building-django-powered-website-django.html

Now lets try this:

http://www.jeffknupp.com/blog/2013/12/18/starting-a-django-16-project-the-right-way/

emacs ~/.bashrc.include&
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/directory-you-do-development-in
source /usr/bin/virtualenvwrapper.sh


http://www.youtube.com/watch?v=zTNA0MtZwso
Python Web Development: Understanding Django for Beginners

More resources

http://blog.arisetyo.com/getting-started-with-python-elasticsearch-client/

http://www.elasticsearch.org/blog/unleash-the-clients-ruby-python-php-perl/#python

http://www.opencrowd.com/blog/post/elasticsearch-django-tutorial/

https://github.com/aparo/django-elasticsearch/blob/master/README.rst

http://spinscale.github.io/elasticsearch/2012-03-jugm.html#/36

http://andrewbrookins.com/tech/one-year-later-an-epic-review-of-pycharm-2-7-from-a-vim-users-perspective/

http://www.jetbrains.com/pycharm/download/index.html

http://media.readthedocs.org/pdf/django/latest/django.pdf

$ ls /usr/lib/python3.3/site-packages/django/bin/django-admin.py
/usr/lib/python3.3/site-packages/django/bin/django-admin.py

sudo ln -s /usr/lib/python3.3/site-packages/django/bin/django-admin.py /usr/local/bin

eric-IDE Tips & Tricks

Eric is a good IDE for Django. It has Highlighting, Autocompletion, CVS & Subversion, Debugger, and Breakpoints.
eric (Python 3) and eric4 (Python 2) can be installed from the official repositories.
To start a new Django Project.
First click on the "Project/new." Then under "Project Type" select Django. After your new django project has been created, Right-click on the "Project Viewer", to the Left, and select "Configure", and in the configuration window set "Project type" to Django.
After that, in eric4's "Settings/Preferences" select Django, from the left, and add this change to the "Console Command."
If KDE,
konsole --workdir `pwd` -e
konsole --workdir `pwd` --noclose -e
This will solve the problem...
/usr/bin/python2: can't open file 'manage.py': [Errno 2] No such file or directory
Note the "Django" menu next to "Project" and "Extras". There you will find Django tools to runserver and sync database.
Now, just play around with it a little. All your Python code will be Added to the first tab of the "Project-Viewer" and your html templates will be opened in the second tab.