본문 바로가기
프로그래밍/Python

004. 파이썬 import error 해결: TypingError, np.arrange

by life_is_egg 2024. 6. 18.
반응형

파이썬에서 pertpy 패키지를 쓰려고 pip로 설치하고 import를 했는데 에러가 계속 뜸.

chatgpt에게도 물어봤으나 파이썬, 패키지 버전 충돌이라며 처음에는 업데이트하라고만 알려줌.🤯

에러메시지를 다시 살펴보니 문제는 매우매우매우매우 간단했음.


결론요약

🍟 np.arrange 옵션의 keyword arguments 삭제하기 🍟

 

에러 메세지에 나온

파일경로( ../../../.conda/envs/pertpy-AT/lib/python3.11/site-packages/decoupler/method_gsva.py)

따라 들어가 np.arrage의 start, stop, step을 삭제하니까 정상적으로 돌아감.

# 기존의 코드
rev_idx = np.abs(np.arange(start=n, stop=0, step=-1, dtype=nb.f4) - n / 2)

# 수정한 코드
rev_idx = np.abs(np.arange(n, 0, -1, dtype=nb.f4) - n / 2)

 


Troubleshooting 과정
TypingError Traceback (most recent call last)
Cell In[3], line 1
----> 1 import pertpy as pt

...

<source elided>
n = mat.shape[1]
rev_idx = np.abs(np.arange(start=n, stop=0, step=-1, dtype=nb.f4) - n / 2)
^

 

에러 메세지 상세 보기 열어보니까 아래와 같이 자세히 알려줌.

즉, nopython 모드에서는 np의 arrange가 'start' 'stop' 'step' 키워드 인수를 받지 않는다고 함.

 

File "../../../.conda/envs/pertpy-AT/lib/python3.11/site-packages/decoupler/method_gsva.py", line 86:

위의 파일 경로를 따라 들어가서 86번째 라인의 코드에서

np.arrage의 option으로 적혀있던 start, stop, step을 삭제하고 저장함.


최종적으로 아래 두 파일의 코드를 수정하니까 성공적으로 돌아감!

1. method_gsva.py의 line 86

2. method_aucell의 line 37

에러 메세지 상세 보기
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function arange>) found for signature:

arange(start=int64, stop=Literalint, step=Literalint, dtype=class(float32))

There are 2 candidate implementations:

Of which 2 did not match due to:
Overload in function 'np_arange': File: numba/np/arrayobj.py: Line 4760.
With argument(s): '(start=int64, stop=int64, step=int64, dtype=class(float32))':
Rejected as the implementation raised a specific error:
TypingError: 'start' parameter is positional only, but was passed as a keyword
raised from /home/.conda/envs/pertpy-AT/lib/python3.11/site-packages/numba/core/typing/templates.py:783
During: resolving callee type: Function(<built-in function arange>)
During: typing of call at /home/.conda/envs/pertpy-AT/lib/python3.11/site-packages/decoupler/method_gsva.py (86)

File "../../../.conda/envs/pertpy-AT/lib/python3.11/site-packages/decoupler/method_gsva.py", line 86:
def nb_get_D_I(mat):
<source elided>
n = mat.shape[1]
rev_idx = np.abs(np.arange(start=n, stop=0, step=-1, dtype=nb.f4) - n / 2)

 

반응형

댓글