개발환경 세팅 중 에러가 발생했다.

tensorflow 설치를 진행하고 프로그램 시작을 하니 다음과 같은 에러가 발생했다.

 

tensorflow.python.framework.errors_impl.AlreadyExistsError: Another metric with the same name already exists.

 

[해결방법]

tensorflow와 keras가 연동되어 버전이 맞지 않으면 발생하는 문제이다.

세팅한 개발환경에서는 tensorflow==2.6.0을 사용하였는데, keras도 2.6.0을 맞춰주었다.

pip install keras==2.6.0

 

[참고링크]

https://precommer.tistory.com/76

 

AlreadyExistsError: Another metric with the same name already exists.오류

환경 오류로 "Another metric with the same name already exists." 라는 오류가 뜨는 경우는 keras가 두개 이상 설치되어 있는경우이다. 해결 방법은 keras를 uninstall 하고나서 재 설치 하면 된다. 1. keras를..

precommer.tistory.com

 

hydralit을 사용하는 도중 불편한 것이 발견되어 오래 사투하게 되었다.

streamlit으로 spinner를 사용하면 불필요한 hydralit의 loader 3개씩이나 뜬다는 것이다!

관련 구글링을 아무리 해봐도 찾지 못해 답답했다.

우연히 함수들을 찾아보다가 발견해버렸다!

 

수정해야할 코드 위치

/opt/conda/lib/python3.8/site-packages/hydralit/loading_app.py

import streamlit as st
from hydralit_components import HyLoader, Loaders
from hydralit.app_template import HydraHeadApp

class LoadingApp(HydraHeadApp):

def run(self,app_target):

    try:
        app_title = ''
        if hasattr(app_target,'title'):
            app_title = app_target.title

        # with HyLoader("Now loading {}".format(app_title), loader_name=Loaders.standard_loaders,index=[3,0,5]):
        app_target.run()
  
    except Exception as e:
        raise e

 

 

[StackOverFlow에 답글 달아주기]

https://stackoverflow.com/questions/71652864/how-to-remove-the-animated-loader-from-hydralit-streamlit

 

How to remove the animated loader from hydralit (streamlit)?

I am using Streamlit to build a web app and with Hydralit I was able to use the multipage function. However, the function came with an animated loader that I would like to remove. What command can ...

stackoverflow.com

아무도 답변하지 않는 질문에 처음으로 댓글을 달아보았다.

도움이 되면 좋겠다.

Streamlit으로 프로토타입 구현 중 에러가 발생했다.

  File "/opt/conda/envs/lib/lib/python3.8/site-packages/streamlit/scriptrunner/script_runner.py", line 475, in _run_script
    exec(code, module.__dict__)
  File "/opt/ml/input/code/project/pipeline/zzolflix.py", line 4, in <module>
    import hydralit as hy
  File "/opt/conda/envs/lib/lib/python3.8/site-packages/hydralit/__init__.py", line 5, in <module>
    from hydralit.hydra_app import HydraApp
  File "/opt/conda/envs/lib/lib/python3.8/site-packages/hydralit/hydra_app.py", line 4, in <module>
    from hydralit.sessionstate import SessionState
  File "/opt/conda/envs/lib/lib/python3.8/site-packages/hydralit/sessionstate.py", line 8, in <module>
    from streamlit.script_run_context import get_script_run_ctx
ModuleNotFoundError: No module named 'streamlit.script_run_context'

라이브러리를 설치하고, hydralit까지 설치해서 가장 기본적인 앱을 실행시켰는데, 해당 에러가 나왔다.

hydralit은 streamlit에 영향을 받는 라이브러리인 것 같다.

streamlit에 버전에 따라 hydralit쪽에서 에러가 발생할 수 있다.

 

[해결방법]

File "/opt/conda/envs/lib/lib/python3.8/site-packages/hydralit/sessionstate.py", line 8, in <module>

이 경로로 이동한 뒤, 소스를 직접 수정해주어야 한다.

#v1.7.0
from streamlit.script_run_context import get_script_run_ctx
#v1.8.0
from streamlit.scriptrunner.script_run_context import get_script_run_ctx

내가 테스트 한 버전은 streamlit==1.9.0 이었다.

그래서 후자로 변경하였더니 에러가 해결되었다.

 

[참고링크]

https://discuss.streamlit.io/t/streamlit-script-run-context-gone-with-1-8/23526/2

 

Streamlit.script_run_context() gone with 1.8?

I have the same problem, it breaks this code here:

discuss.streamlit.io

https://stackoverflow.com/questions/70813915/error-importing-hydralit-modulenotfounderror-no-module-named-streamlit-repor

 

Error importing hydralit: "ModuleNotFoundError: No module named 'streamlit.report_thread'"

I installed Hydralit, but when I try to import I get the following error: "ModuleNotFoundError: No module named 'streamlit.report_thread'". Interestingly I can import and use

stackoverflow.com

 

pyaudio library 설치에서 에러가 발생했다.

pip install pyaudio

 

에러 메세지를 타이틀만 기록해서 상세한 에러 메세지는 stackoverflow에서 가지고 왔다.

Searching for pyaudio
Reading http://pypi.python.org/simple/pyaudio/
Reading http://people.csail.mit.edu/hubert/pyaudio/
Best match: pyaudio 0.2.4
Downloading http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.4.tar.gz
Processing pyaudio-0.2.4.tar.gz
Running PyAudio-0.2.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0Tetss/PyAudio-0.2.4/egg-dist-tmp-PYy9T8
In file included from /usr/include/python2.7/Python.h:8:0,
                 from src/_portaudiomodule.c:30:
/usr/include/python2.7/pyconfig.h:1155:0: warning: "_POSIX_C_SOURCE" redefined
/usr/include/features.h:214:0: note: this is the location of the previous definition
src/_portaudiomodule.c:31:23: fatal error: portaudio.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1

 

해결방법

apt-get install portaudio19-dev -y

 

참고 링크

https://stackoverflow.com/questions/5921947/pyaudio-installation-error-command-gcc-failed-with-exit-status-1

 

Pyaudio installation error - 'command 'gcc' failed with exit status 1'

I'm running Ubuntu 11.04, Python 2.7.1 and wanted to install Pyaudio. So I ran, $ sudo easy_install pyaudio in the terminal and the process exited with following error messages, Searching for py...

stackoverflow.com

 

file 이름을 pickle.py 로 하면 안된다는 것이다.

[ 참고 블로그 ]

https://nadocoding.tistory.com/57

 

[파이썬 기본편] 8-4.pickle

컴퓨터로 문서 작업을 하다가 갑자기 프로그램이 먹통이 되면서 '응답 없음' 상태로 빠지는 아찔한 경험은 아마 한 번씩 해보셨을 겁니다. 운이 좋으면(?) 잠시 후에 정상으로 돌아오기도 하지만

nadocoding.tistory.com

 

python 전용으로 binary file로 다뤄주는 모듈 pickle을 공부하다가 아주 간단한 에러를 직면했다.

file 이름을 pickle.py 로 하면 안된다는 것이다.

참고한 블로그의 내용이다!

Q) pickle 사용 시 아래와 같이 에러가 나는데 어떻게 해야 하나요?
AttributeError: partially initialized module 'pickle' has no attribute 'dump or load' (most likely due to a circular import)

A) 소스코드 작성중인 파일명을 pickle.py 로 하셨을텐데 my_pickle.py 등과 같이 변경해주셔야 합니다. 사용하시려는 모듈과 동일한 이름으로 파일을 생성하면 import 시에 동일한 경로에 있는 이 파일을 먼저 인식하게 되기 때문에 그렇습니다.

이를 응용했을 때, 다른 것에도 똑같이 파이썬 기본 내장 모듈을 사용한 파일명은 사용하지 않아야 할 것이다!

ex) pickle.py  logging.py  configparser.py  argparse.py

 

깃허브에서 파이썬 기본에 대한 예제를 기록한 레포 링크이다.

https://github.com/updaun/PythonBasic/tree/master/file_handing

 

GitHub - updaun/PythonBasic: PythonBasic

PythonBasic. Contribute to updaun/PythonBasic development by creating an account on GitHub.

github.com

 

사용하던 라이브러리에서 에러가 발생하였다.

 

[ Error Message ] 

urllib.error.HTTPError: HTTP Error 410: Gone

 

Youtube Downloader 프로그램을 만들어서 사용하고 있는데, 동영상이 다운로드 되지 않는 문제가 발생하였다.

 

원인을 분석해보니, 유투브가 업데이트 되면서 pytube 라이브러리가 그것을 수용하지 못한 거 같다.

조금 기다려보니 pytube 라이브러리 개발자가 오류를 수정하였다.

 

[ 조치사항 ]

[ 내용 수정 ] 

- 최신 버전의 pytube로 업데이트한다. ( 11.0.0 버전 다운로드 )

pip install -U pytube

 

그리고 라이브러리만 수정하여 사용하려고 했는데,

테스트 과정에서 한 가지 더 오류가 발견되었다.

해상도가 아주 낮게 동영상이 다운되는 문제가 발생했는데,

youtube 다운로드 구문에 " .filter(res="720p") " 를 추가하여 해상도를 지정하였다.

YouTube(youtube_url).streams.filter(res="720p").first().download('./Downloads/')

 

[ 향후 보완 사항 ]

현재 프로그램을 다른 사용자가 사용했을 때 불편할 수 있는 점이 있는데,

1. pytube 라이브러리가 없으면 자동으로 설치를 하는 구문을 추가하자.

2. pytube 버전이 11.0.0 미만이면 업데이트 알림을 제공하도록 하자.

python 3.7.7 버전에서 dlib 라이브러리 설치에서 Error가 발생하였다.

조치하는데 생각보다 많은 시간이 걸려서 나와 같은 사람이 있을 것 같아, 글을 작성해본다.

[error 내용]

ERROR: Command errored out with exit status 1: 'C:\Users\jdu\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\jdu\\AppData\\Local\\Temp\\pip-install-zsqykg6o\\dlib_aebf39f99fce459994812d9033b95078\\setup.py'"'"'; __file__='"'"'C:\\Users\\jdu\\AppData\\Local\\Temp\\pip-install-zsqykg6o\\dlib_aebf39f99fce459994812d9033b95078\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\jdu\AppData\Local\Temp\pip-record-nk1s1red\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\jdu\anaconda3\Include\dlib' Check the logs for full command output.

dlib 설치

pip install dlib

당연히 설치 될 줄 알았지만 설치가 되지 않았다면, 아래의 조치 방법을 한 뒤, 설치를 해보자.

최후의 방법도 준비되어 있다!

 

[조치방법]

1. CMake 설치

pip install cmake

 

2. Visual Studio 설치

https://visualstudio.microsoft.com/ko/downloads/

 

Windows 및 Mac용 Visual Studio 2019 다운로드

프로젝트에 대해 알려주시면 적절한 다운로드 및 자습서를 찾는 데 도움을 드리겠습니다.

visualstudio.microsoft.com

Visual Studio 설치시 Windows용 C++ CMake 도구가 체크되어 있는지 확인한다.

CMake를 설치하고 다시 시도해보자.

pip install dlib

그럼에도 안되면 최후의 방법이다.

3. dlib-19.17.0-cp37-cp37m-win_amd64.whl 다이렉트 설치(Python 3.7버전만 가능)

dlib-19.17.0-cp37-cp37m-win_amd64.whl
2.97MB

해당 파일을 다운로드 받은 뒤, 원하는 경로에 위치 시킨다.

cmd에서 해당 경로로 들어가 준다!

pip install dlib-19.17.0-cp37-cp37m-win_amd64.whl

 

[ 새롭게 추가한 부분! ] 

4. python 3.8 버전용도 새롭게 찾아 내었다!

dlib-19.19.0-cp38-cp38-win_amd64.whl
3.19MB

해당 파일을 다운로드 받은 뒤, 원하는 경로에 위치 시킨다.

cmd에서 해당 경로로 들어가 준다!

pip install dlib-19.19.0-cp38-cp38-win_amd64.whl

 

각각의 파이썬 버전마다 해당 파일이 존재하는 듯하다.

다른 파이썬 버전을 사용한다면, 해당 설치 파일을 찾아서 설치해야한다.

이 글이 도움이 되길 바란다.

dlib 설치 후 돌려본 오프소스!

눈 깜빡임 감지 인공지능 모델을 돌려보다 에러가 발생했다.

[ Error Message ]

predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')

RuntimeError: Unable to open shape_predictor_68_face_landmarks.dat

dlib에서 어떤 파일을 호출하는 것에서 에러가 발생한 듯하다.

얼굴을 찾는 모델인 것 같다.

구글링을 한 결과, stack overflow의 글을 잘 읽고 참고하였다.

https://stackoverflow.com/questions/64643440/how-do-i-fix-runtimeerror-unable-to-open-shape-predictor-68-face-landmarks-dat

 

How do I fix "RuntimeError: Unable to open shape_predictor_68_face_landmarks.dat" while using google colab?

I am writing the following Python code in Google Colaboratory and get an error: Code: import cv2 import dlib cap = cv2.VideoCapture(0) hog_face_detector = dlib.get_frontal_face_detector()

stackoverflow.com

[ Linux ]

!wget   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 # DOWNLOAD LINK

!bunzip2 /content/shape_predictor_68_face_landmarks.dat.bz2

datFile =  "/content/shape_predictor_68_face_landmarks.dat"

 

[ Windows ]

인터넷 웹 주소창에 해당 주소를 입력하여 파일을 다운로드 받아준다.

http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2

 

7-zip을 활용하여 압축을 해제한다.

[7zip Download link] https://www.7-zip.org/download.html

 

Download

Download .7z Any / x86 / x64 LZMA SDK: (C, C++, C#, Java)

www.7-zip.org

 

압축을 해제하면, "shape_predictor_68_face_landmarks.dat" 파일이 나오는데, 

이 파일을 사용하고자하는 경로에 두고 호출하면 된다.

나는 working directory에 바로 넣고,

predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')

로 호출하여 사용하였다.

 

그리하여 눈깜빡 감지 모델 오픈 소스를 돌려볼 수 있었다!

 

다른 분들도 해메지 않고 금방 극복하길 바란다! :)

+ Recent posts