Sunday, 20 November 2016

AlisJK:ODKScan

Status : Draft


python


Ketika install, pastikan menggunakan python 2.7.9 jika menggunakan python > 2.7.9 sepertinya ketika  penulis menggunakan python 2.7.12 maka akan muncuk error seperti ini ketika menjalankan celery :

alisjk@openthinklabs002$:celery --version
Traceback (most recent call last):
  File "/usr/local/bin/celery", line 9, in <module>
    load_entry_point('celery==3.0.17', 'console_scripts', 'celery')()
  File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 12, in main
    maybe_patch_concurrency()
  File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 7, in maybe_patch_concurrency
    from celery.platforms import maybe_patch_concurrency
  File "/usr/local/lib/python2.7/dist-packages/celery/platforms.py", line 22, in <module>
    from kombu.utils.encoding import safe_str
  File "/usr/local/lib/python2.7/dist-packages/kombu/utils/__init__.py", line 17, in <module>
    from uuid import UUID, uuid4 as _uuid4, _uuid_generate_random
ImportError: cannot import name _uuid_generate_random

Untuk kompilasi python 2.7.9 di Ubuntu dapat membaca [1] atau jika menggunakan Ubuntu 16.04 64 bit, Anda bisa mengunduh .deb nya disini.

Install dengan perintah :

sudo dpkg -i python-2.7.9_2.7.9-1_amd64.deb 


Jika ingin uninstall, perintah :

sudo  dpkg -r python-2.7.9

Instalasi


ODKScan_Webapp berhasil diinstall dengan paket-paket berikut :
alisjk@openthinklabs:~$ pip list  --format=columns 
Package         Version 
--------------- --------
amqp            1.0.13  
anyjson         0.3.3   
billiard        2.7.3.34
celery          3.0.17  
cffi            1.9.1   
cryptography    1.7.2   
Django          1.5.1   
django-celery   3.0.17  
enum34          1.1.6   
idna            2.2     
image           1.5.5   
ipaddress       1.0.18  
kombu           2.5.16  
meld3           1.0.2   
MySQL-python    1.2.5   
nose            1.3.7   
olefile         0.44    
PIL             1.1.7   
pip             9.0.1   
pyasn1          0.2.2   
pycparser       2.17    
pyOpenSSL       16.2.0  
python-dateutil 1.5     
pytz            2016.10 
setuptools      33.1.1  
six             1.10.0  
spec            1.3.1   
supervisor      3.2.0   
textile         2.1.5   
vine            1.1.3   
virtualenv      15.1.0  
xlrd            0.8.0  

Untuk PIL 1.1.7 bisa didownload di : http://effbot.org/media/downloads/PIL-1.1.7.tar.gz

Dengan VirtualEnv


Lihat [3]

sudo pip install virtualenvwrapper
sudo nano ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bash_profile
mkvirtualenv -p /opt/python279/bin/python scanadmin --no-site-packages
cd apps/scanadmin/ODKScan_webapp
workon scanadmin
pip install -r requirements.pip

Untuk uji coba, jalankan perintah ini di direktori scanadmin :

python manage.py runserver 8080

Jika muncul error seperti dibawah, 


Request Method:GET
Request URL:http://scanadmin.np:8080/admin/ODKScan_webapp/formimage/
Django Version:1.5.1
Exception Type:TemplateDoesNotExist
Exception Value:
admin/login.html
Exception Location:/home/wildan/.virtualenvs/scanadmin/lib/python2.7/site-packages/django/template/loader.py in find_template, line 139
Python Executable:/home/wildan/.virtualenvs/scanadmin/bin/python
Python Version:2.7.9

Install ulang semua requirements dengan perintah :

pip install -r requirements.pip --ignore-installed --force-reinstall --upgrade --no-cache-dir

lalu coba lagi :

python manage.py runserver 8080

Apache + mod_wsgi

Berikut adalah konfigurasi virtualhost yang digunakan : 

<VirtualHost *:8080>
ServerAdmin info@openthinklabs.com
    ServerName  scanadmin.np

    WSGIScriptAlias / /apps/scanadmin/scanadmin/wsgi.py
        # Serve static files:
        DocumentRoot /apps/scanadmin/ODKScan_webapp/
        Alias /static/admin /home/wildan/.virtualenvs/scanadmin/django/contrib/admin/static/admin
        <Directory "/home/wildan/.virtualenvs/scanadmin/django/contrib/admin/static/admin">
          Order Allow,Deny
          Allow From All

 Require all granted
        </Directory>
       Alias /static /apps/scanadmin/ODKScan_webapp/static
      <Directory "/apps/scanadmin/ODKScan_webapp/static">
        Order Allow,Deny
        Allow From All Require all granted
      </Directory>
   
   
      #A bunch of stuff to make the server run in daemon mode, which is better
      WSGIApplicationGroup scanadmin
      WSGIDaemonProcess scanadmin user=www-data group=www-data threads=10 maximum-requests=100 python-home=/home/wildan/.virtualenvs/scanadmin  python-path=/apps/scanadmin shutdown-timeout=100
      WSGIProcessGroup scanadmin
     <Directory /apps/scanadmin/scanadmin>
        #if enabled allows cors requests from github hosted apps.
        #SetEnvIf Origin "^(.*[(github\.com)(c9\.io)])$" ORIGIN_SUB_DOMAIN=$1
        #Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN
        <Files wsgi.py>
          Order deny,allow
          Allow from all
 Require all granted
        </Files>
     </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

celery worker supervisor

Referensi

  1. Installation of Python 2.7.9 in Ubuntu, http://python.openthinklabs.com/2017/06/pyside-instalasi.html
  2. ODKScan_webapp, https://github.com/OpenThink-Labs/ODKScan_webapp
  3. Deploy Django on Apache with Virtualenv and mod_wsgi, http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/
  4. Setting up Django and your web server with uWSGI and nginx, http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
  5. Deploy Django Applications Using uWSGI and Nginx on Ubuntu 14.04, https://www.linode.com/docs/websites/nginx/deploy-django-applications-using-uwsgi-and-nginx-on-ubuntu-14-04
  6. Wiring uWSGI to work with Django and nginx on Ubuntu 16.04, http://serverfault.com/questions/775965/wiring-uwsgi-to-work-with-django-and-nginx-on-ubuntu-16-04
  7. No module named _sysconfigdata_nd, http://stackoverflow.com/questions/15608236/eclipse-and-google-app-engine-importerror-no-module-named-sysconfigdata-nd-u

No comments:

Post a Comment