manywaypark's Blog
개발, 검색, 함수

문제:

macport로 python36을 설치하고, 안내에 따라 py36-readline을 설치했는데 아래 처럼 crash가 났다.

$ python

Python 3.6.1 (default, Mar 22 2017, 15:53:21) 

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> ''.join(sorted('azbasdfasdf'))

Python(4369,0x7fffa0cba3c0) malloc: *** error for object 0x10592a4f0: pointer being freed was not allocated

*** set a breakpoint in malloc_error_break to debug

Abort trap: 6



해결:

$ sudo port uninstall py36-readline

$ sudo port install python36 +readline


python36 package를 설치하고 나면 py36-readline도 꼭 설치하라는 식의 메시지가 나오는데 이거 잘못된 것인 듯


ref: https://trac.macports.org/ticket/53360


happy hackin'

problem:

python에서 matplotlib를 사용하여 그래프를 화면에 출력하려고 할때 아래와 같은 오류 메시지가 나오고 제대로 안되는 경우가 있다.


>>> import tkinter

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/home/dhpark/.asdf/installs/python/3.5.2/lib/python3.5/tkinter/__init__.py", line 35, in <module>

    import _tkinter # If this fails your Python may not be configured for Tk

ImportError: No module named '_tkinter'


__init__.py 파일에서 모듈 import에 실패한다는 것인데 해결 방법은 찾아보면 간단하다.


solution #1:

우분투의 경우 python3-tk, tk-dev 패키지 두개만 깔면 해결된다.

그러나 이 방법은 package manager를 통해서 python3를 깔았을때에만 적용되는 것으로 보인다.


solution #2:

요즘은 버전간의 자유로운 전환을 위해서 virtualenvasdf같은 유틸리티의 도움을 받는 경우가 많은데 (물론 내경우도 포함), 이 경우에는 #1의 해법이 통하지 않는다.

상기 패키지2개를 설치한 후에 python을 지우고 다시 깔아야한다.

asdfvirtualenv같이 설치과정에서 compile을 거치는 놈들은 시스템에 설치안된 것을 생략해버리는 것으로 추측된다. 정확한 원인은 좀 더 봐야겠지만 귀찮다.


happy hackin'

문제:
python에서 unittest 모듈을 써서 unit test를 할 때 다음과 같이 썼다.

if __name__ == '__main__':
unittest.main()


수행하면 다음과 같이 테스트케이스 다 실행하고 OK 뜬 후에 exception이 났다. 좀 찜찜했다.

......
......
Ran 2 tests in 12.545s

OK
Exception in thread "main" Traceback (most recent call last):
  File "D:\comms_share\csm-gui-test\sikuli\csmLogin.sikuli\csmLogin.py", line 11
1, in <module>
    unittest.main()
  File "D:\comms_share\csm-gui-test\sikuli-script.jar\Lib\unittest.py", line 768
, in __init__
  File "D:\comms_share\csm-gui-test\sikuli-script.jar\Lib\unittest.py", line 806
, in runTests
SystemExit: False


해결:
여기저기 뒤져봤더니 IDLE 문제라고 이미 알려져있었다.
다음과 같이 쓰면 된다.

class FooTest(unittest.TestCase) :
def setUp(self) :
......
def tearDown(self):
......
def testSomething() :
......

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(FooTest)  
unittest.TextTestRunner(verbosity=2).run(suite)


python 버전 정보는 다음과 같다

Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin


refs:
1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

03-28 15:58