Python

Solve vcvarsall.bat Python Windows installation

30 Nov , 2014  

When installing python modules in Windows 8, this errors is very common and very hard to find solution. I spent 2 hours only to solve this issues

1
Unable to find vcvarsall.bat

The solution is quite straight-forward:

1. Install Visual Studio 2008
VC Setup http://go.microsoft.com/?linkid=7729279
VS 2008 : http://download.microsoft.com/download/E/8/E/E8EEB394-7F42-4963-A2D8-29559B738298/VS2008ExpressWithSP1ENUX1504728.iso

2. Install Microsoft SDK
http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&displaylang=en

3. After installing, setup your global environment variables:

1
VS90COMNTOOLS = J:\Program Files (x86)\Microsoft Visual Studio 9.0\VC

Also, add into PATH

1
J:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools;J:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin

If your OS Path is C:\ then just replace J: with C:.

Then all your problem should gone. Btw, there some modules that required header files that not covered by Windows:
https://pypi.python.org/pypi/python-ldap/

Reference:

http://springflex.blogspot.com/2014/02/how-to-fix-valueerror-when-trying-to.html

Install Python Header (NO NEED)
http://www.microsoft.com/en-us/download/details.aspx?id=44266

Django

Setup Queue in Django using Celery and RabbitMQ

23 Nov , 2014  

I’m using Ubuntu for setup queue in Django using celery and rabbitmq. Go to console and we need to install rabbitmq at first:

1. RabbitMQ

1
2
3
4
wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc
sudo apt-get update
sudo apt-get install rabbitmq-server

To adjust system limits (in particular the number of open file handles), edit the file /etc/default/rabbitmq-server to invoke ulimit when the service is started, for example:

1
ulimit -n 1024

Will set the maximum number of file open handles for the service process to 1024 (the default).

Invoke rabbitmqctl stop to stop the server.
Invoke rabbitmqctl status to check whether it is running.

Some detail tutorial
http://docs.dotcloud.com/tutorials/python/django-celery/
https://github.com/ServiceStack/rabbitmq-windows

2. Django Celery

1
pip install django-celery

Then add “djcelery” in INSTALLED_APPS. Then do migration by :

1
python manage.py migrate djcelery

,

Ubuntu

Cleanup local branch and sync with Remote Git

22 Nov , 2014  

Here is git command to cleanup local branch and sync with remote :

1
git branch --merged | grep -v "\*" | egrep -v "master|dev" | xargs -n 1 git branch -d

Python

Update reference models in Haystack problem solved

22 Nov , 2014  

When we put reference model in part of index and get updated, it will NOT changed in main model. Here is some example:

models.py

1
2
3
4
5
class UserProfile(CommonInfo):
    city = models.ForeignKey(City)

    def __unicode__(self):
        return unicode(self.code)

With search indexes :

userprofile.txt

1
{{ object.city.name }}

When “CITY” models is updated, let say “CHICAGO” into “UTAH”. We search on UserProfile, the city name will be still “CHICAGO”. Whooppss!

The solution, whenever City updated, we need to update UserProfile as well. Create signal to save UserProfile whenever City updated with post_save()

Uncategorized

Bootstrap Chosen

17 Nov , 2014  

Here is the links:

http://akrabat.com/software/styling-a-chosen-select-to-fit-bootstrap-3-better/

Javascript

Jquery Icheck checkbox checked or not

17 Nov , 2014  

Here is snippet to check if checkbox is checked or not in Jquery iCheck:

1
2
3
4
5
$('input[name="some-input-name"]').on('ifToggled', function (event) {
           if ($(this).is(':checked')) {
               alert('checked');
            }
        });

Python

Solve ImportError: cannot import name IncompleteRead

12 Nov , 2014  

When doing “pip install -r requirement.txt”, suddenly i got this erros out of nowhere. Fyi, I’m suspecting upgrade “requests” module may cause this issue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 351, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2363, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2088, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead

The solution is :

1
2
3
sudo apt-get remove python-pip
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py

Django

TypeError: __init__() got an unexpected keyword argument ‘preserve_default’

12 Nov , 2014  

Quickfix to solve ;

1
2
3
4
5
6
7
8
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "D:\Python\vasham\dashboards\migrations\0004_auto_20141112_1644.py", line 7, in <module>
    class Migration(migrations.Migration):
  File "D:\Python\vasham\dashboards\migrations\0004_auto_20141112_1644.py", line 18, in Migration
    preserve_default=True,
TypeError: __init__() got an unexpected keyword argument 'preserve_default'

Is

1
pip install django --upgrade

Uncategorized

Installing Process Designer in Windows 8 / Server 2012

4 Nov , 2014  

After download Process Designer from IBM BPM, then you can go :

1
C:\Program Files\IBM\Installation Manager\eclipse

Execute eclipse. Then in preferences, just add the repository to Process Designer folder :

1
D:\IBM\IBM Process Designer\IMPD85\repository.config

Uncategorized

Setup IBM BPM in Azure

4 Nov , 2014  

Here is step to setup IBM BPM in Azure.

1. Setup VM
2. Enable ports using Azure Powershell

After login into Windows:
1. Enable policy rules for IBM BPM ports
2. Install DB2
3. Create database

http://www-01.ibm.com/support/knowledgecenter/SSFPJS_8.5.0/com.ibm.wbpm.imuc.ebpm.doc/topics/db_create_nd_win_db2.html

After installed, run “db2cmd”:

1
2
3
4
5
db2
create database PDWDB automatic storage yes  using codeset UTF-8 territory US pagesize 32 k;
connect to PDWDB
UPDATE DB CFG FOR PDWDB USING LOGFILSIZ 4096 DEFERRED
UPDATE DB CFG FOR PDWDB USING LOGSECOND 64 DEFERRED

Repeat for BPMDB and CMNDB

4. Install BPM (Don’t forget to setup your DNS)
5. Update BPM into version 8.5.0.1
6. Start BPM and everything fine!

Windows

Change DNS Hostname Window Server 2012

2 Nov , 2014  

To change Windows Server 2012 Hostname (I use for BPM installation), please go to :

1. Control Panel
2. System Security
3. System Properties
4. Change your computer name

change DNS 2

change DNS