본문 바로가기

프로그래밍 관련/[Python] 간단 해결

(11)
[Tensorflow] Failed to load the native TensorFlow runtime. - 증상 Traceback (most recent call last): File "C:\Users\User\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * ... ImportError: DLL load failed: 지정된 모듈을 찾을 수 없습니다. Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/errors for some common reasons and solu..
[Python] glob 정규식으로 폴더 및 파일 제외 - 해결 # glob exclude folder import glob f = glob.glob(pathImageRoot/[!_]*) print(f) # ['pathImageRoot/image.jpg', 'pathImageRoot/text.txt', 'pathImageRoot/file.exe', ...] ''' # example simple regular expression 1) /**/* : 현재 디렉토리 및 하위 디렉토리에 존재하는 모든 파일 리스트화 2) /*[txt$|jpg$]: 현재 디렉토리 내에 존재하는 모든 .txt, .jpg 파일 리스트화 3) /text[1-3].txt: 현재 디렉토리 내에 있는 text1.txt, text2.txt 파일 리스트화 ''' - 참고 (StackOverflow)..
[Python] PermissionError: [Errno 13] Permission denied: Path... - 증상 # Python에서 파일 오픈 시 권한 오류(Permission denied)가 발생하는 대부분의 경우는 다음과 같다 ''' 1. 실제로 파일을 Read할 수 있는 권한이 없을 때 2. 파일이 아니라 폴더를 지정 했을 때 3. 파일이 없을 때 ''' - 해결 # 위의 오류는 대부분 파일이 아닌, 폴더를 직접 지정하는 경우에 발생하므로, 경로를 다시 확인해보면 대부분 해결 된다. # 1. 만약, 폴더 하위에 있는 파일의 경로를 쉽게 모두 알아내고 싶다면 imutils 패키지를 사용해보자. from imutils import paths files = list(paths.list_files(pathFileRoot)) print(files) ''' ['pathImageRoot/a/image.jpg', ..
[Python] UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 17533: illegal multibyte sequence - 증상 # CP949로 인코딩 되어있는 파일 Open시 with open(path, 'r') as f: f = f.read() print(f) ''' Traceback (most recent call last): Error Message... UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 17533: illegal multibyte sequence ''' - 해결 # Open시 Parameter(mode, encoding)를 통해 해결 # mode 'rt' = default with open(path, 'rt', encoding='UTF-8') as f: f = f.read() print(f) ''' File Read And ..
[Python] cv2.imread 한글 경로 인식 문제 - 증상 #imagePath에 한글 경로 존재 시 import cv2 img = cv2.imread(imagePath, -1) # img = None print(np.shape(img)) # () - 해결 # numpy fromfile, cv2 imdecode를 사용하여 해결 import numpy as np import cv2 ff = np.fromfile(imagePath, np.uint8) img = cv2.imdecode(ff, cv2.IMREAD_UNCHANGED) # img = array print(np.shape(img)) # (w, h, scale) - 참고 (OpenCV API Documentation) OpenCV: Image file reading and writing For TIFF..
[Python] json.dumps() 한글 > 유니코드로 저장될 때 - 증상 import json dict = {'key' : '한글'} print (json.dumps(dict)) # {'key' : '\ud55c\uae00'} - 해결 # json. dumps 옵션으로 'ensure_ascii=False' 추가 import json dict = {'key' : '한글'} print (json.dumps(dict, ensure_ascii=False)) # {'key' : '한글'}
[Python] OSError: mysql_config not found (Ubuntu 16.04) - 증상 Ubuntu OS에서 mysqlclient 설치 시 아래 에러 발생 > pip install mysqlclient Collecting mysqlclient Using cached mysqlclient-1.4.6.tar.gz (85 kB) ERROR: Command errored out with exit status 1: command: /root/anaconda3/envs/bottle/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sv3lnj0y/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-sv3lnj0y/mysqlclient/set..
[CUDA] Windows10에서 간단하게 CUDA 사용률 확인하는 방법 - 사전 필요 프로그램 1) CUDA Toolkit 2) cuDNN SDK 본인의 Nvidia 그래픽카드에 맞는 CUDA, cuDNN을 설치한다. - CUDA 사용율 확인 방법 1) 작업관리자 (Ctrl + Shift + ESC) 2) 성능 탭 > GPU 3) 선택 항목(↓표시) 중 1개를 Cuda로 변경 또는, 1) CMD (커맨드라인 입력창) 2) nvidia-smi 입력 3) GPU-Util 확인
[Python] Tensorflow 실행 시 CUBLAS_STATUS_ALLOC_FAILED 등의 그래픽카드 메모리 문제 해결 - 증상 Tensorflow 실행 시 1) CUDA_OUT_OF_MEMORY 2) CUBLAS_STATUS_ALLOC_FAILED 3) Blas GEMM launch failed 등의 에러 발생 - 원인 - Tensorflow는 실행 시 기본적으로 프로세서에 GPU의 메모리 전부를 미리 할당 - 해결 import tensorflow as tf ''' 1) tf.__version__ = 2.0.0 ''' gpu_devices = tf.config.experimental.list_physical_devices('GPU') for device in gpu_devices: tf.config.experimental.set_memory_growth(device, True)
[Python] 판다스(Pandas) DataFrame / Print 출력 수 설정 - 증상 Python에서 Pandas DataFrame print시 콘솔 창에 [0, 0, ... 0, 0]등으로 행, 열이 일부분 생략되어 표시 - 해결 import pandas as pd # 양의 정수 입력 시 해당 수 만큼 표시 # 행 pd.set_option('display.max_rows', 10) # 열 pd.set_option('display.max_columns', 10)