레이블이 Python인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Python인 게시물을 표시합니다. 모든 게시물 표시

2017년 7월 26일 수요일

Mac 아나콘다 환경에서 opencv3 - Pyhon3 설치

설치환경
OS : Mac OSX Sierra (10.12.6)
Python : 3.6.2
Anconda : Custom
opencv 를 설치하려고 conda 리스트를 확인하던중 버전이 없던 것으로 확인되어 



anaconda search -t conda opencv3

표시된 목록으로 확인한 몇몇으로는 현재 Python 버전과 맞지 않아 실패..

conda search -c conda-forge --spec 'opencv=3*'

구글링을 통해 conda-forge 에 Python 3.6 버전에 상응하는 opencv 버전 확인

conda install -y -c conda-forge opencv

로 설치 했으나,,,,

import cv2 실행시

>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Applications/anaconda3/envs/data/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so, 2): Library not loaded: @rpath/libopenblasp-r0.2.19.dylib
  Referenced from: /Applications/anaconda3/envs/data/lib/libopencv_hdf.3.2.0.dylib
  Reason: image not found

Error …

site 2 를 통해 해결

conda update --all -c conda-forge

Site 1 에서 습득한 예제를 토대로 실행 확인
우선 아래 사진을 clouds.jpg로 저장
 다음 아래 code 작성:
1 import cv2
2
3 print("OpenCV version:")
4 print(cv2.__version__)
5
6 img = cv2.imread("clouds.jpg")
7 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
8
9 cv2.imshow("Over the Clouds", img)
10 cv2.imshow("Over the Clouds - gray", gray)
11
12 cv2.waitKey(0)
13 cv2.destroyAllWindows()

demo.py로 저장
아래 명령으로 실행
1 python demo.py

실행결과는 아래와같고 ESC 를 누르면 종료

2017년 7월 24일 월요일

Mac Anaconda 와 Python3 환경에서 pygame 설치하는법


Mac Sierra Anaconda 와 Python3 환경에서 pygame 설치 
환경
OS : Mac OS Sierra (10.12.5)
Python Version : 3.6.1
Anaconda version : custom  
Pygame 라이브러리를 설치하기 위한 Process 정리 (작동확인)

필요사항

Xcode optional package 를 먼저 설치.
터미널에서
> xcode -select —install
설치 완료되면 계속해서 진행
anaconda-python 를 설치하면  python3 , pip 는 설치 되어 있다.
터미널에서
python —version
which python
which pip
확인해보면 /Users/~/anaconda/bin 으로  되어 있음. (~는 home계정)

Package manager 설치 (이미 설치 했으면 Pass)

Mac 에서는 Homebrew 를 대부분 설치해서 사용(dependancy 자동 해결)
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

Install Pygame

다음에서 발췌 Pygame Issue Tracker thread.
첫번째로  Mercurial version control system 을 설치해준다. :
brew install mercurial
git version control 도 설치해 준다. :
brew install git
이제 pygame dependencies 를 설치해준다. :
brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi
마지막으로 :
pip install hg+http://bitbucket.org/pygame/pygame

Test sample code (on sublime text3)

import pygame,sys

pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello Pygame World!')
while True: # main game loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

샘플 코드 실행시 정상 작동 확인..

이 글은 Evernote에서 작성되었습니다. Evernote는 하나의 업무 공간입니다. Evernote를 다운로드하세요.