이 블로그 검색

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