치명적인 Python 오류: PyThreadState_Get: 현재 스레드 없음

Olorunfemi Akinlua 2023년6월21일
  1. PyThreadState_Get: 현재 스레드 없음 오류의 원인
  2. sudo를 사용하여 PyThreadState_Get: no current thread 오류 해결
  3. otool을 사용하여 PyThreadState_Get: no current thread 오류 해결
치명적인 Python 오류: PyThreadState_Get: 현재 스레드 없음

우리의 로컬 컴퓨터에는 주어진 시간에 해당 버전에 제한되거나 새로운 기능만 수행할 수 있는 다른 Python 버전 설치가 있을 수 있습니다.

모든 종속성이 있는 버전 컨텍스트 내에서 코드를 작성하고 해당 코드가 다른 Python 버전 컨텍스트에서 실행되는 경우 문제가 발생할 수 있습니다.

이러한 문제 중 하나는 PyThreadState_Get: no current thread이며, 이 기사에서는 이 문제의 원인과 로컬 Mac/Linux PC에서 해결하는 방법에 대해 설명합니다.

PyThreadState_Get: 현재 스레드 없음 오류의 원인

여러 Python 설치에는 서로 다른 모듈과 종속성이 연결되어 있지만 Python 코드를 실행할 때 잘못된 Python 바인딩이 PC에서 제공하는 시스템에 연결될 수 있습니다. 이 시나리오는 macOS를 사용할 때 자주 발생합니다.

따라서 올바른 Python(모듈 포함)이 코드를 실행하고 올바른 모듈을 시스템 Python에 연결하는지 확인해야 합니다.

sudo를 사용하여 PyThreadState_Get: no current thread 오류 해결

여러 Python 설치가 있는 경우 다른 라이브러리에서 Python을 사용할 수 있으며 PyThreadState_Get: 현재 스레드 없음 오류 메시지를 해결하기 위해 활성 Python을 기본 라이브러리로 이전에 호출한 Python 설치로 변경할 수 있습니다. 당신의 코드.

활성 Python 설치를 변경하려면 아래 sudo 명령을 사용할 수 있습니다.

sudo port select --list python

명령의 출력:

Available versions for python:
    none
    python26-apple
    python27
    python27-apple (active)
    python34

위의 출력에서 활성 Python 설치는 python27-apple이며 종속성과 모듈을 보유하는 Python 설치를 전환하려면 python34가 필요합니다.

python34로 변경하려면 아래 sudo 명령을 사용할 수 있습니다.

sudo port select python python34

위의 명령을 실행한 후 --list 명령을 사용하여 제대로 작동하는지 확인할 수 있습니다.

sudo port select --list python

이제 명령 출력에 python34가 활성 상태임을 표시해야 합니다.

Available versions for python:
    none
    python26-apple
    python27
    python27-apple
    python34 (active)

otool을 사용하여 PyThreadState_Get: no current thread 오류 해결

종종 코드를 실행할 때 PyThreadState_Get: no current thread 오류 메시지의 주요 원인은 라이브러리(import 문)를 인식하지 못하는 다른 Python 설치와 함께 사용하기 때문입니다. otoolinstall_name_tool 유틸리티를 사용하여 문제를 해결할 수 있습니다.

이 문제를 해결하려면 대체 Python 설치와 함께 Python 라이브러리(예: Leap Motion)를 사용해야 하며 원하는 Python 설치를 참조하도록 라이브러리의 로더 경로를 업데이트해야 합니다.

먼저 otool 명령을 사용하여 현재 로더 경로를 확인합니다.

otool -L LeapPython.so

명령의 출력:

LeapPython.so:
    @loader_path/LeapPython.so (compatibility version 0.0.0, current version 0.0.0)
    /Library/Frameworks/Python.framework/Versions/3.4/Python (compatibility version 3.4.0, current version 3.4.0)
    @loader_path/libLeap.dylib (compatibility version 0.7.0, current version 2.0.1)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

따라서 현재 Python 위치/참조인 /Library/Frameworks/Python.framework/Versions/3.4/Python을 원하는 Python 설치로 변경하고 업데이트해야 합니다. 이를 위해서는 install_name_tool 명령을 사용해야 합니다.

명령을 실행하면 사용하려는 라이브러리에 대한 새 Python 설치 위치를 참조했습니다.

install_name_tool -change /Library/Frameworks/Python.framework/Versions/3.4/Python \
/usr/local/Cellar/python/3.8.8/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib \
LeapPython.so

이제 PyThreadState_Get: no current thread 오류 메시지 없이 Python 코드를 실행할 수 있습니다.

Olorunfemi Akinlua avatar Olorunfemi Akinlua avatar

Olorunfemi is a lover of technology and computers. In addition, I write technology and coding content for developers and hobbyists. When not working, I learn to design, among other things.

LinkedIn

관련 문장 - Python Error