Py_DECREF() 함수는 PyObject 변수의 참조의 값을 줄어주며,
python 자체의 garbage collector를 호출하여, 사용하지 않는 변수를 청소하는 역활을 한다.
아무튼, PyObject를 선언하고 사용후 종료하게 되면
Exception AttributeError: "'module' object has no attribute 'YouTubeService'" in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
import 라는 키워드로 python에서는 모듈을 불러온다.
이녀석을 c/api에서 사용하는 방법은 크게 두가지가 있다.
하나는 문자열로 인터프리트 방식으로 import 명령을 실행하는 것과
PyRun_SimpleString("import hashlib");
다른 하나는, __main__ 모듈을 추가하고 그에 원하는 모듈을 import 하는 방식이다.
PyObject * mainModule = PyImport_AddModule("__main__");
PyObject * hashlibModule = PyImport_ImportModule("hashlib");
PyModule_AddObject(mainModule, "hashlib", hashlibModule);
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback
머 실행결과는 나오니까 (단순한 print 테스트) 경고라고 했지만
아마 import os 등을 하면 에러가 났을것으로 생각이 된다.
해결방법은 (Python2.6 기준 기본값으로) /usr/local/lib/python2.6 디렉토리를 복사해주면 된다.
(python2.6 아래에는 각종 *.py *.pyo *.pyc
컴파일이 되었으므로, pyc나 pyo는 py에 비해 속도 향상이 있으며
pyc는 py를 -O 옵션을 통해(모든 py파일에서 pyc를 생성)
pyo는 py를 -OO 옵션을 통해 생성이 가능하다.
(이부분은 확인필요. py 파일을 이상없이 실행가능하면 컴파일 가능하며, 자동으로 pyc가 생성된다고 하지만, 밑에
-O 옵션으로 디렉토리 내의 모든 py를 pyc로 컴파일 한다는 내용도 존재한다.)
pyc는 assert 문만을 삭제함으로 속도 향상폭은 크지 않으며
pyo는 pyc에 비해 __doc__ 구분도 삭제하므로 더욱 작이진다.(일부 프로그램은 __doc__ 구분 사용할수 있으니 주의)
6.1.3. “Compiled” Python files
As an important speed-up of the start-up time for short programs that use a lot
of standard modules, if a file called spam.pyc exists in the directory
where spam.py is found, this is assumed to contain an
already-“byte-compiled” version of the module spam. The modification time
of the version of spam.py used to create spam.pyc is recorded in
spam.pyc, and the .pyc file is ignored if these don’t match.
Normally, you don’t need to do anything to create the spam.pyc file.
Whenever spam.py is successfully compiled, an attempt is made to write
the compiled version to spam.pyc. It is not an error if this attempt
fails; if for any reason the file is not written completely, the resulting
spam.pyc file will be recognized as invalid and thus ignored later. The
contents of the spam.pyc file are platform independent, so a Python
module directory can be shared by machines of different architectures.
Some tips for experts:
When the Python interpreter is invoked with the -O flag, optimized
code is generated and stored in .pyo files. The optimizer currently
doesn’t help much; it only removes assert statements. When
-O is used, allbytecode is optimized; .pyc files are
ignored and .py files are compiled to optimized bytecode.
Passing two -O flags to the Python interpreter (-OO) will
cause the bytecode compiler to perform optimizations that could in some rare
cases result in malfunctioning programs. Currently only __doc__ strings are
removed from the bytecode, resulting in more compact .pyo files. Since
some programs may rely on having these available, you should only use this
option if you know what you’re doing.
A program doesn’t run any faster when it is read from a .pyc or
.pyo file than when it is read from a .py file; the only thing
that’s faster about .pyc or .pyo files is the speed with which
they are loaded.
When a script is run by giving its name on the command line, the bytecode for
the script is never written to a .pyc or .pyo file. Thus, thet
startup time of a scrip may be reduced by moving most of its code to a module
and having a small bootstrap script that imports that module. It is also
possible to name a .pyc or .pyo file directly on the command
line.
It is possible to have a file called spam.pyc (or spam.pyo
when -O is used) without a file spam.pyfor the same module.
This can be used to distribute a library of Python code in a form that is
moderately hard to reverse engineer.
The module compileall can create .pyc files (or .pyo
files when -O is used) for all modules in a directory.
아마 2.4와 2.6이 혼합되어 설치되어있고, 2.6이 정상설치가 되지 않은듯 싶다.
옵션에 따라서 이러한 오류가 발생했다.
# gcc py.c -I/usr/local/include/python2.6 -L/usr/local/lib/libpython2.6.a
/tmp/cc88iTD7.o: In function `main':
py.c:(.text+0x12): undefined reference to `Py_Initialize'
py.c:(.text+0x26): undefined reference to `PyRun_SimpleStringFlags'
py.c:(.text+0x2b): undefined reference to `Py_Finalize'
collect2: ld returned 1 exit status
# gcc py.c -I/usr/local/include/python2.6 -lpython2.6
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_tmpnam':
./Modules/posixmodule.c:7180: warning: the use of `tmpnam_r' is
dangerous, better use `mkstemp'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_tempnam':
./Modules/posixmodule.c:7135: warning: the use of `tempnam' is
dangerous, better use `mkstemp'
/usr/local/lib/libpython2.6.a(signalmodule.o): In function
`timeval_from_double':
./Modules/signalmodule.c:106: undefined reference to `floor'
./Modules/signalmodule.c:107: undefined reference to `fmod'
./Modules/signalmodule.c:106: undefined reference to `floor'
./Modules/signalmodule.c:107: undefined reference to `fmod'
/usr/local/lib/libpython2.6.a(floatobject.o): In function `float_pow':
Objects/floatobject.c:972: undefined reference to `pow'
/usr/local/lib/libpython2.6.a(floatobject.o): In function
`float_divmod':
Objects/floatobject.c:856: undefined reference to `fmod'
/usr/local/lib/libpython2.6.a(floatobject.o): In function `float_rem':
Objects/floatobject.c:834: undefined reference to `fmod'
/usr/local/lib/libpython2.6.a(longobject.o): In function
`PyLong_FromString':
Objects/longobject.c:1610: undefined reference to `log'
Objects/longobject.c:1610: undefined reference to `log'
/usr/local/lib/libpython2.6.a(dynload_shlib.o): In function
`_PyImport_GetDynLoadFunc':
Python/dynload_shlib.c:94: undefined reference to `dlsym'
Python/dynload_shlib.c:130: undefined reference to `dlopen'
Python/dynload_shlib.c:141: undefined reference to `dlsym'
Python/dynload_shlib.c:133: undefined reference to `dlerror'
/usr/local/lib/libpython2.6.a(thread.o): In function
`_pythread_pthread_set_stacksize':
Python/thread_pthread.h:519: undefined reference to
`pthread_attr_setstacksize'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_release_lock':
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_free_lock':
Python/thread_pthread.h:320: undefined reference to `sem_destroy'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_allocate_lock':
Python/thread_pthread.h:296: undefined reference to `sem_init'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_acquire_lock':
Python/thread_pthread.h:351: undefined reference to `sem_trywait'
Python/thread_pthread.h:349: undefined reference to `sem_wait'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_start_new_thread':
Python/thread_pthread.h:171: undefined reference to
`pthread_attr_setstacksize'
Python/thread_pthread.h:181: undefined reference to `pthread_create'
Python/thread_pthread.h:197: undefined reference to `pthread_detach'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_release_lock':
Python/thread_pthread.h:374: undefined reference to `sem_post'
Python/thread_pthread.h:374: undefined reference to `sem_post'
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_allocate_lock':
Python/thread_pthread.h:296: undefined reference to `sem_init'
Python/thread_pthread.h:296: undefined reference to `sem_init'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_forkpty':
posixmodule.c:(.text+0x2653): undefined reference to `forkpty'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_openpty':
posixmodule.c:(.text+0x26fc): undefined reference to `openpty'
/usr/local/lib/libpython2.6.a(complexobject.o): In function `_Py_c_abs':
Objects/complexobject.c:214: undefined reference to `hypot'
/usr/local/lib/libpython2.6.a(complexobject.o): In function `_Py_c_pow':
Objects/complexobject.c:143: undefined reference to `hypot'
Objects/complexobject.c:144: undefined reference to `pow'
Objects/complexobject.c:145: undefined reference to `atan2'
Objects/complexobject.c:151: undefined reference to `cos'
Objects/complexobject.c:152: undefined reference to `sin'
Objects/complexobject.c:148: undefined reference to `exp'
Objects/complexobject.c:149: undefined reference to `log'
collect2: ld returned 1 exit status
x86 계열에서 메모리 팍팍 쓰면서 속도를 향상시켜준다는,
마법의(!?) JIT(Just In Time) compiler 이다.
결론은.. x86이 아니면 안되는군 ㅠ.ㅠ
What you can do with it
In short: run your existing Python software much faster, with no change in your source.
Think of Psyco as a kind of just-in-time (JIT) compiler, a little bit like what exists for other languages, that emit machine code on the fly instead of interpreting your Python program step by step. The difference with the traditional approach to JIT compilers is that Psyco writes several version of the same blocks (a block is a bit of a function), which are optimized by being specialized to some kinds of variables (a "kind" can mean a type, but it is more general). The result is that your unmodified Python programs run faster.
Benefits
2x to 100x speed-ups, typically 4x, with an unmodified Python interpreter and unmodified source code, just a dynamically loadable C extension module.
Drawbacks
Psyco currently uses a lot of memory. It only runs on Intel 386-compatible processors (under any OS) right now. There are some subtle semantic differences (i.e. bugs) with the way Python works; they should not be apparent in most programs.
머, 중요한건 일단
1. wxPython은 Python이 있어야 작동을 하고.
2. wxPython은 wxWidgets 의 wrapper 라는 것 (그러니까 wxWidget도 설치 되어있어야 하겠지?)
음.. 근데 버전에 따라 다른가? 이제는 glib 와 gtk+ 가 필요하다고 하는군!
The first thing you'll need are the glib and gtk+
libraries. Before you run off and download the sources check your
system, you probably already have it. Most distributions of Linux come
with it and you'll start seeing it on many other systems too now that
Sun and others have chosen GNOME as the desktop of choice. If you don't
have glib and gtk+ already, you can get the sources here. Build and install them following the directions included.
In order to use the wxGLCanvas you'll need to have either OpenGL or the Mesa3D library on your system. wxPython's wx.glcanvas.GLCanvas only provides the GL Context and a wx.Window to put it in, so you will also need the PyOpenGL Python extension modules as well, if you want to use OpenGL.
If you are building wxPython yourself and don't care to use
OpenGL/Mesa then you can easily skip building it and can ignore this
step. See the build instructions for details.
Python 2.6 이라고 명시한 이유는, 3.0 에서는 없어지거나 이름이 바뀌었기 때문이다.
htmllib Deprecated since version 2.6: The htmllib module has been removed in Python 3.0. urlib
The urllib module has been split into parts and renamed in
Python 3.0 to urllib.request, urllib.parse,
and urllib.error. httplib
The httplib module has been renamed to http.client in Python
3.0. The 2to3 tool will automatically adapt imports when converting
your sources to 3.0.
아무튼, 파이썬 프로젝트 분석시에 버전 정보가 애매모호하면 htmllib가 존재하면 2.6.x 대라고 이해하면 되겠다.(?)