이 블로그 검색

2015년 9월 8일 화요일

Kivy - Buildozer로 Android APK 만들기

가장먼저 buildozer install하기
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python2.7 setup.py install

인스톨이 완료되면 초기화를 실행한다.
buildozer init

init를 완료하고 나면 buildozer.spec 파일이 생성되는데  정보를 적절하게 입력해준다.


[app]

# (str) Title of your application
title = Kivy Python Interpreter

# (str) Package name
package.name = KivyPythonInterpreter

# (str) Package domain (needed for android/ios packaging)
package.domain = enurisoft.com

# (str) Source code where the main.py live
source.dir = /home/mataeoh/Work/PythonProject/Kivy/ScrollBar

# (list) Source files to include (let empty to include all the files)
source.include_exts = ttf,py,png,jpg,atlas,kv

# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
#version.regex = __version__ = '(.*)'
#version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
version = 1.2.0

# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = kivy

# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy

# (list) Garden requirements
#garden_requirements =

# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png

# (str) Icon of the application
#icon.filename = %(source.dir)s/icon/kivy-icon-128.png

# (str) Supported orientation (one of landscape, portrait or all)
orientation = portrait

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 1


#
# Android specific
#

# (list) Permissions
#android.permissions = INTERNET

# (int) Android API to use
#android.api = 14

# (int) Minimum API required (8 = Android 2.2 devices)
#android.minapi = 8

# (int) Android SDK version to use
#android.sdk = 21

# (str) Android NDK version to use
#android.ndk = 9c

# (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True

# (str) Android NDK directory (if empty, it will be automatically downloaded.)
#android.ndk_path =

# (str) Android SDK directory (if empty, it will be automatically downloaded.)
#android.sdk_path =

# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
#android.p4a_dir =

# (list) python-for-android whitelist
#android.p4a_whitelist =

# (str) Android entry point, default is ok for Kivy-based app
#android.entrypoint = org.renpy.android.PythonActivity

# (list) List of Java .jar files to add to the libs so that pyjnius can access
# their classes. Don't add jars that you do not need, since extra jars can slow
# down the build process. Allows wildcards matching, for example:
# OUYA-ODK/libs/*.jar
#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar

# (list) List of Java files to add to the android project (can be java or a
# directory containing the files)
#android.add_src =

# (str) python-for-android branch to use, if not master, useful to try
# not yet merged features.
#android.branch = master

# (str) OUYA Console category. Should be one of GAME or APP
# If you leave this blank, OUYA support will not be enabled
#android.ouya.category = GAME

# (str) Filename of OUYA Console icon. It must be a 732x412 png image.
#android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png

# (str) XML file to include as an intent filters in <activity> tag
#android.manifest.intent_filters =

# (list) Android additionnal libraries to copy into libs/armeabi
#android.add_libs_armeabi = libs/android/*.so
#android.add_libs_armeabi_v7a = libs/android-v7/*.so
#android.add_libs_x86 = libs/android-x86/*.so
#android.add_libs_mips = libs/android-mips/*.so

# (bool) Indicate whether the screen should stay on
# Don't forget to add the WAKE_LOCK permission if you set this to True
#android.wakelock = False

# (list) Android application meta-data to set (key=value format)
#android.meta_data =

# (list) Android library project to add (will be added in the
# project.properties automatically.)
#android.library_references =

#
# iOS specific
#

# (str) Name of the certificate to use for signing the debug version
# Get a list of available identities: buildozer ios list_identities
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"

# (str) Name of the certificate to use for signing the release version
#ios.codesign.release = %(ios.codesign.debug)s


[buildozer]

# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1


#    -----------------------------------------------------------------------------
#    List as sections
#
#    You can define all the "list" as [section:key].
#    Each line will be considered as a option to the list.
#    Let's take [app] / source.exclude_patterns.
#    Instead of doing:
#
#[app]
#source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
#
#    This can be translated into:
#
#[app:source.exclude_patterns]
#license
#data/audio/*.wav
#data/images/original/*
#


#    -----------------------------------------------------------------------------
#    Profiles
#
#    You can extend section / key with a profile
#    For example, you want to deploy a demo version of your application without
#    HD content. You could first change the title to add "(demo)" in the name
#    and extend the excluded directories to remove the HD content.
#
#[app@demo]
#title = My Application (demo)
#
#[app:source.exclude_patterns@demo]
#images/hd/*
#
#    Then, invoke the command line with the "demo" profile:
#
#buildozer --profile demo android debug


디버그로 APK 빌드하기
buildozer android debug

릴리즈로 빌드하기
buildozer android release

Instructions for creating a signed, release APK, suitable for the Google Play Store

Fields

  • my-project - The directory for your project
  • my-new-key - The name of the key you generate
  • my-alias - A short alias name for the key
  • MyProject - The name of your project, and APK
  • version - The version of this APK (not Kivy version)

Commands

$ cd ~
$ keytool -genkey -v -keystore ./keystores/<my-new-key>.keystore -alias <my-alias> -keyalg RSA -keysize 2048 -validity 10000
$ cd ~/<my-project>
$ source venv/bin/activate
$ buildozer android release
$ cd ~
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ./keystores/<my-new-key>.keystore ./<my-project>/bin/<MyProject>-<version>-release-unsigned.apk <my-alias>
$ <key-password>
$ ~/.buildozer/android/platform/android-sdk-21/build-tools/22.0.1/zipalign -v 4 ./<my-project>/bin/<MyProject>-<version>-release-unsigned.apk ./<my-project>/bin/<MyProject>.apk


빌드도중 에러발생시
Traceback (most recent call last):
File "build.py", line 507, in 
make_package(args)
File "build.py", line 356, in make_package
subprocess.check_call([ANT, arg])
File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ant', 'debug']' returned non-zero exit status 1

Android SDK Build-tools를 revision 20으로 다운을 받고 완료되면 buildozer를 재실행한다.

  1. Run ~/.buildozer/android/platform/android-sdk-21/tools/android to launch the Android SDK Manager.
  2. Click the Deselect All link at the bottom of the window, and check the box next to "Android SDK Build-tools -- 20". screenshot from 2014-09-27 13 17 13
  3. Click the Install 1 package... button.
  4. Click Accept License and then click the Install button. screenshot from 2014-09-27 13 19 19

2015년 7월 29일 수요일

[Blender] 블렌더에서 Sculpting 퍼포먼스 향상 시키기

1. First off, 'ctrl+alt+u' to bring up user preferences. Under the 'System' settings make sure 'VBOs' is enabled.
( 시스템 설정으로 가서 VBOs를 체크한다!)

2. !! Important : In 'Object Data' tab, make sure 'Double Sided' is off.

( Double Sided를 해제한다.)

3. Stay in solid view. Do not use textures. Do not use the 'matcap' method. Do not use 'texture solid'

( solid 뷰 모드로만 작업할것!! 텍스쳐 등등은 느리다.. )

2015년 6월 22일 월요일

[ Python / Ubuntu] ubuntu에서 python 실행시 PYTHON_EGG_CACHE 에러

/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/mataeoh/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable)

linux에서 python 소스를 실행하다 보면 위와 같은 에러 메시지가 발생하는 경우 egg 폴더를 셋팅해주어야 한다. 해결방법은 있지만 복잡하니깐 Eclipse or PyCharm과 같은 IDE를 사용하도록하자.. 알아서 해준다!


Solution ))

From my investigations it turns out that some eggs are packaged as zip files, and are saved as such in Python's site-packages directory.
These zipped eggs need to be unzipped before they can be executed, so are expanded into the PYTHON_EGG_CACHE directory which by default is ~/.python-eggs (located in the user's home directory). If this doesn't exist it causes problems when trying to run applications.
There are a number of fixes:
  1. Create a .python-eggs directory in the user's home directory and make it writable for the user.
  2. Create a global directory for unzipping (eg. /tmp/python-eggs) and set the environment variable PYTHON_EGG_CACHE to this directory.
  3. Use the -Z switch when using easy_install to unzip the package when installing.

2015년 6월 18일 목요일

[ PyOpenCL/PyOpenGL ] AttributeError: 'numpy.ndarray' object has no attribute 'buffers'

pyopencl 예제를 실행하다 보면 아래와 같이 vbo(vertex buffer object)의 buffers를 참조하려다 에러가 나는 경우가 있다.

원인은 vbo 객체를 생성시 기본적으로는 PyOpenGL 라이브러리를 참조하나 PyOpenGL-accelerate가 설치되어 있을경우 PyOpenGL-accelerate로부터 vbo를 생성하는데, 3.0.2버전까지는 vbo객체에 buffers 멤버가 있었으나 3.1.0 버전부터 사라져 버려 AttributeError이 발생한다.

Traceback (most recent call last):
  File "D:\Development\PythonProject\PythonExamples\PyOpenCL\nbody_simulation\main.py", line 135, in <module>
    p2 = window()
  File "D:\Development\PythonProject\PythonExamples\PyOpenCL\nbody_simulation\main.py", line 59, in __init__
    self.cle.loadData(pos_vbo, col_vbo, vel)
  File "D:\Development\PythonProject\PythonExamples\PyOpenCL\nbody_simulation\part2.py", line 37, in loadData
    self.pos_cl = cl.GLBuffer(self.ctx, mf.READ_WRITE, int(self.pos_vbo.buffers[0]))
  File "vbo.pyx", line 177, in OpenGL_accelerate.vbo.VBO.__getattr__ (src\vbo.c:2754)
AttributeError: 'numpy.ndarray' object has no attribute 'buffers'

[ Python ] PyOpenGL, glutInit 초기화시 에러가 발생할때..

* Error Message

Traceback (most recent call last):
  File "main.py", line 35, in __init__
    glutInit(sys.argv)
  File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 324, in glut
Init
    _base_glutInit( ctypes.byref(count), holder )
TypeError: 'NoneType' object is not callable


위와 같이 glutInit(sys.argv)를 실행하면 에러가 나는 경우가 있다.
해결방법은 http://freeglut.sourceforge.net/ 사이트를 방문하여 freeglut 라이브러리를 다운받아 설치하면 된다.
설치경로는 소스코드가 있는 폴더에 freeglut.dll을 복사해주거나 아래와 같이 OS 시스템에 맞는 폴더에 복사해주면 된다.

Window x64(64bit) 일 경우는 C:\Windows\SysWOW64
Window x86(32bit) 일 경우는 C:\Windows\System32

주의 : 당연한 얘기지만 freeglut.dll 파일의 경우 64bit와 32bit 버전이 있다. OS의 환경에 맞추는 것이 아니라 python이 32bit or 64bit 인지에 맞춰서 freeglut파일을 복사해 주어야 한다.

2015년 6월 17일 수요일

[ Python ] Eclipse에서 Python 모듈의 최신버전이 적용이 안될때...

가끔 이클립스에서 작업을 하다보면 python의 모듈을 최신버전으로 설치했음에도 예전버전이 로드되는 경우가 있다.
이럴때는 Window -> Preference -> Interpreters -> Python Interpreters 로 들어가서 PYTHONPATH를 새로 갱신해주면 문제는 해결된다.
interpreter 목록을 모두지우고 새로 만들거나 path를 모두 지우고 apply를 눌러 다시 생성하는 방법이 있다.

[ PyOpenCL ] Ubuntu에 PyOpenCL 설치하기

참고링크 : http://wiki.tiker.net/PyOpenCL/Installation/Linux/Ubuntu

- nvidia인경우 cuda toolkit을 설치하면 opencl 라이브러리도 함께 설치된다.
- numpy, setuptools 모듈을 설치해준다.

1. python configure.py 실행하면 siteconf.py 파일이 생성된다.
2. siteconf.py  파일 수정
    BOOST_INC_DIR = ['/usr/include/boost']
    BOOST_LIB_DIR = ['/usr/lib/x86_64-linux-gnu']
    BOOST_COMPILER = 'gcc43'
    BOOST_PYTHON_LIBNAME = ['boost_python-py27']
    USE_SHIPPED_BOOST = False
    CL_TRACE = False
    CL_ENABLE_GL = True
    CL_ENABLE_DEVICE_FISSION = True
    CL_INC_DIR = ['/usr/local/cuda-6.5/include']
    CL_LIB_DIR = ['/usr/local/cuda-6.5/lib64']
    CL_LIBNAME = ['OpenCL']
    CXXFLAGS = []
    LDFLAGS = []
3. sudo python setup.py install

* 중요 : 빌드는 정상적으로 되었는데 python을 실행하여 import pyopencl을 실행하면 아래와 같은 에러가 발생하는 경우가 있다. 정확한 원인은 모르겠으나 pip를 통해 설치된 pytools는 삭제하고 apt-get install 명령을 사용해 python-pytools를 설치해주면 문제는 해결된다.
또한 pyopencl 소스가 있는곳에서 import pyopencl을 실행하면 _cl 모듈을 찾을수없다는 에러가 발생하므로 작업폴더를 변경해주면 된다.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyopencl-2015.1-py2.7-linux-x86_64.egg/pyopencl/__init__.py", line 762, in <module>
    _add_functionality()
  File "/usr/local/lib/python2.7/dist-packages/pyopencl-2015.1-py2.7-linux-x86_64.egg/pyopencl/__init__.py", line 379, in _add_functionality
    from pytools import memoize_method
  File "/usr/local/lib/python2.7/dist-packages/pytools-2014.3.5-py2.7.egg/pytools/__init__.py", line 5, in <module>
    from six.moves import range, zip, intern, input
ImportError: cannot import name intern

1. sudo pip uninstall pytools
2. sudo apt-get install python-pytools