[PYTHON] Mobile Applicaiton development with IBM Bluemix Kinetise (1)

** What is Kinetise ** Kinetise is a Mobile Application development service available on Bluemix (December 2015) As of the month). By linking with Web Service by Python and Django, we have realized quick development of Mobile Application that can process CRUD.

** What I want to convey in this article ** For Python and Django Web Services, deploying the Bluemix Python runtime, and building applications with Kinetise, refer to the Kinetise guide Starters SDK for the actual work procedure. And how to solve the problem. Authentication is not implemented. When actually developing it, it is necessary to consider it separately.

** Working environment ** I am working in a Windows 7 SP1 64bit environment. For Python, Django, etc., please refer to requirements.txt below. It's important to use the version included in Github's Python buildpack for deploying on Bluemix. Using a version that is not included in the buildpack will result in compatibility errors during deployment, complicating problem isolation. Python 2.7 is used for rf_alter_api.zip, which is a library dedicated to Kinetise. This is because rf_alter_api.zip uses a function modified in Python 3 (eg urlparse in Python 2.7 was renamed to urllib.parse in Python 3), which causes an error (as of December 2015).

** Work procedure ** The procedure is as follows. I will explain each work.

  1. Eclipse and Python related preparation (introduction, creation of Python project)
  2. Python code modification
  3. Check operation with POSTMAN
  4. Deploy to Bluemix Python runtime (http://qiita.com/yoshiono/items/2fb5a4505e3561458854)
  5. Development and build of Mobile Application with Kinetise (working hard)

** 1. Preparation related to Eclipse and Python (introduction, creation of Python project) ** 1.1. Install Eclipse and Python by referring to the Procedure of the great ancestors. Note that this article uses Eclipse Marse.1 (4.5.1) and Python 2.7.10. For the Python development plugin for Eclipse, you can use the PyDev environment from the beginning by selecting the Python version of Pleiades All in One.

1.2. Build a virtual environment (env3) in My Documents and install the required modules. For the convenience of virtual environment and Eclipse, please refer to the articles of our predecessors. Since multiple versions of Python have already been installed on this work PC and multiple virtual environments have been built, commands such as virtualenv and pip are specified with absolute paths to avoid confusion. In addition, since vitalenv has already been installed, we are checking the version with freeze. If it has not been installed, install it before starting work. Below is the log. The user name is hoge.

Command log


C:\Users\hoge\Documents>C:\Python27\Scripts\pip.exe freeze -l
virtualenv==13.1.2

C:\Users\hoge\Documents>C:\Python27\Scripts\virtualenv.exe env3
New python executable in env3\Scripts\python.exe
Installing setuptools, pip, wheel...done.

C:\Users\hoge\Documents>cd env3\Scripts

C:\Users\hoge\Documents\env3\Scripts>activate
(env3) C:\Users\hoge\Documents\env3\Scripts>pip install django
Collecting django
  Using cached Django-1.9-py2.py3-none-any.whl
Installing collected packages: django
Successfully installed django-1.9

(env3) C:\Users\hoge\Documents\env3\Scripts>pip install djangorestframework
Collecting djangorestframework
  Using cached djangorestframework-3.3.2-py2.py3-none-any.whl
Installing collected packages: djangorestframework
Successfully installed djangorestframework-3.3.2

(env3) C:\Users\hoge\Documents\env3\Scripts>pip install markdown
Collecting markdown
Installing collected packages: markdown
Successfully installed markdown-2.6.5

(env3) C:\Users\hoge\Documents\env3\Scripts>pip install django-filter
Collecting django-filter
  Using cached django_filter-0.11.0-py2.py3-none-any.whl
Installing collected packages: django-filter
Successfully installed django-filter-0.11.0

(env3) C:\Users\hoge\Documents\env3\Scripts>pip install yattag
Collecting yattag
Installing collected packages: yattag
Successfully installed yattag-1.5.2

(env3) C:\Users\hoge\Documents\env3\Scripts>pip install drf-extensions
Collecting drf-extensions
Requirement already satisfied (use --upgrade to upgrade): djangorestframework>=2
.3.5 in c:\users\hoge\documents\env3\lib\site-packages (from drf-extensions)

Installing collected packages: drf-extensions
Successfully installed drf-extensions-0.2.8

(env3) C:\Users\hoge\Documents\env3\Scripts>pip freeze -l
Django==1.9
django-filter==0.11.0
djangorestframework==3.3.2
drf-extensions==0.2.8
Markdown==2.6.5
wheel==0.24.0
yattag==1.5.2

1.3. Start Eclipse. Specify C: \ Users \ hoge \ workspace_env3 as the workspace. Window-Select Python Interpreter in Settings, the interpreter name is python27, and the interpreter executable is C: \ Users \ hoge \ Documents \ env3 \ Scripts \ python.exe. Unzip the rf_alter_api.zip downloaded from kinetise and copy the rf_alter_api folder to C: \ Users \ hoge \ Documents \ env3 \ Lib \ site-packages. At that time, uncheck read-only in the folder properties. It works without removing it. A write error may occur because a pyc file is generated in this folder? The purpose is to dispel the anxiety.

1.4. In Eclipse Select File-New-Project PyDev-PyDev Django project and create a new Pydev project with the project name kinetise. Select python27 as the interpreter. Right-click on the kinetise project and select Django-Migrate (Django> = 1.7) manage.py migrate. Similarly, select Django-Create Application (manage.py start app) and specify comments for the Django app name. (Supplement) If you are building a virtual environment with Python 3 virtualenv in 1.2, the kinetise project will not work properly because the PYTHONPATH of the kinetise project contains Python 3 modules that do not support kinetise. To solve it, you need to start over with the Python 2.7 vitalenv. Also, the series of work is equivalent to django-admin startproject kinetise ~ manage.py startapp comments on the command line, which allows you to use manage.py on Eclipse. By the way, regarding the creation of a new project in Eclipse, please be aware that if you select the Pydev project from the beginning, manage.py will not be created and the subsequent work will be complicated. If the final screen is the sqlite3 setting screen, manage.py has been created. You can add manage.py yourself, but it's easier to recreate it from scratch with File-New-Project. Also, the rf_alter_api folder contains objects for Kinetise's Web Service, which must be referenced via PYTHONPATH. In other words, the path of the rf_alter_api folder must be included in the "PYTHONPATH for execution" in Eclipse and in the PYTHONPATH environment variable in run.sh for Bluemix.

This concludes the explanation of Eclipse and Python related preparation (introduction, creation of Python project). Next, I will explain PYTHON code correction.

Recommended Posts

Mobile Applicaiton development with IBM Bluemix Kinetise (3)
Mobile Applicaiton development with IBM Bluemix Kinetise (1)
Mobile Applicaiton development with IBM Bluemix Kinetise (2)
Mobile Applicaiton development with IBM Bluemix Kinetise (1)
Virtualize (isolate) IBM i python development environment with chroot
Development digest with Django
Bluemix Python Microservices Development
Virtualize (isolate) IBM i python development environment with chroot
Development digest with Django
Bluemix Python Microservices Development