본문 바로가기

분류 전체보기980

Python OpenCV를 사용할 때 cv2 모듈을 찾을 수 없습니다., Cannot find module cv2 when using OpenCV 질문 나는 Raspberry Pi에서 Occidentalis 운영 체제 (Raspbian의 변형)에 OpenCV를 설치했습니다. jayrambhia의 이 스크립트를 사용했습니다. 이 스크립트는 버전 2.4.5를 설치했습니다. Python 프로그램에서 import cv2를 시도하면 다음과 같은 메시지가 표시됩니다: pi@raspberrypi~$ python cam.py Traceback (most recent call last) File "cam.py", line 1, in import cv2 ImportError: No module named cv2 cv2.so 파일은 /usr/local/lib/python2.7/site-packages/...에 저장되어 있습니다. /usr/local/lib에는 pyth.. 2023. 12. 5.
Python 문자열에서 퍼센트(%)를 선택적으로 이스케이프하는 방법은 무엇인가요?, How can I selectively escape percent (%) in Python strings? 질문 나는 다음과 같은 코드를 가지고 있습니다. test = "have it break." selectiveEscape = "Print percent % in sentence and not %s" % test print(selectiveEscape) 원하는 출력 결과는 다음과 같습니다: Print percent % in sentence and not have it break. 실제로 발생한 일은 다음과 같습니다: selectiveEscape = "Use percent % in sentence and not %s" % test TypeError: %d format: a number is required, not str 답변 >>> test = "have it break." >>> selectiveEscap.. 2023. 12. 5.
Python Requests 라이브러리의 로그 메시지를 비활성화하는 방법은 무엇인가요?, How do I disable log messages from the Requests library? 질문 기본적으로 Requests 파이썬 라이브러리는 다음과 같은 형식으로 로그 메시지를 콘솔에 출력합니다: Starting new HTTP connection (1): example.com http://example.com:80 "GET / HTTP/1.1" 200 606 저는 일반적으로 이러한 메시지에 관심이 없으며, 이를 비활성화하거나 Requests의 상세도를 줄이는 가장 좋은 방법은 무엇일까요? 답변 requests의 로깅 레벨을 구성하는 방법을 알아냈습니다. 이는 표준 logging 모듈을 통해 수행됩니다. 나는 메시지를 경고 이상으로만 로깅하도록 구성하기로 결정했습니다: import logging logging.getLogger("requests").setLevel(logging.WARNING.. 2023. 12. 4.
Python 파이썬 셸 내에서 tensorflow가 GPU 가속을 사용하는지 확인하는 방법은 무엇인가요?, How to tell if tensorflow is using gpu acceleration from inside python shell? 질문 저는 우분투 16.04에서 두 번째 답변인 여기의 ubuntu의 기본 apt cuda 설치를 사용하여 tensorflow를 설치했습니다. 이제 제 질문은 tensorflow가 실제로 gpu를 사용하는지 어떻게 확인할 수 있는지입니다. 저는 gtx 960m gpu를 가지고 있습니다. import tensorflow를 실행하면 다음과 같은 출력이 나옵니다. I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so l.. 2023. 12. 4.