본문 바로가기

Contact English

【Python】 파이썬 주요 트러블슈팅 [101-120]

 

파이썬 주요 트러블슈팅 [101-120]

 

추천글 : 【Python】  파이썬 목차 


 

101. AttributeError: 'builtin_function_or_method' object has no attribute 'default'

 (package) 해결 방법 : torch_geometric 버전을 2.6.1에서 1.7.2 또는 2.0.0으로 downgrade (ref)

 

 

102. ImportError: Could not import sentence_transformers python package. Please install it with `pip install sentence-transformers`.

 (package) 문제 상황 : embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")

(package) 해결 방법 : huggingface_hub 버전을 0.24.6으로 downgrade 혹은 

 

pip uninstall huggingface_hub
pip uninstall sentence_transformers
pip install --force-reinstall sentence-transformers==2.2.2 huggingface_hub==0.16.4

 

 

103. TypeError: 'type' object is not subscriptable

(package) 해결 방법 : 파이썬 버전을 3.8에서 3.9로 upgrade 

 

 

104. AttributeError: module 'numpy.lib' has no attribute 'pad'

(package) 해결 방법 1. numpy 버전 downgrade 

(grammar) 해결 방법 2. numpy.lib.pad 부분을 numpy.pad로 변경

 

 

105. ValueError: <COMPRESSION.JPEG: 7> requires the 'imagecodecs' package

 (package) 해결 방법 : pip install imagecodecs 또는 conda install -c conda-forge imagecodecs 

 

 

106. AttributeError: module 'scipy' has no attribute 'io'

 (grammar) 문제 상황 

 

from scipy.sparse import csr_matrix

sparse_dat = csr_matrix(dat)
scipy.io.mmwrite("sparse_matrix.mtx", sparse_dat)

 

(grammar) 해결 방법 

 

from scipy.sparse import csr_matrix
from scipy.io import mmwrite

sparse_dat = csr_matrix(dat)
mmwrite("sparse_matrix.mtx", sparse_dat)

 

 

107. InvalidIndexError: Reindexing only valid with uniquely valued Index objects

(grammar) 해결방법 : adata.var_names_make_unique() 

 

 

108. ModuleNotFoundError: No module named 'graph_tool'

(package) 해결 방법 : conda install -c conda-forge graph-tool (ref)

제언 : pip로는 설치 방법이 주어져 있지 않아 패키지 충돌 문제를 많이 경험함. graph-tool 혹은 graph_tool 패키지가 쓰일 때면 ChatGPT로 다른 코드로 paraphrase하면서 사용하고 있음

 

 

109. ModuleNotFoundError: No module named 'abc_atlas_access'

 (package) 해결 방법 : pip install git+https://github.com/alleninstitute/abc_atlas_access.git

 

 

110. ImportError: /.../libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent

(package) 원인 : 이 에러는 PyTorch 라이브러리가 설치된 Intel oneDNN/JIT 관련 심볼을 못 불러와서 생기는 전형적인 PyTorch–Intel MKL/OpenMP 충돌 문제

 (package) 해결 방법 : pytorch 버전 맞추기

 

## as an example
pip uninstall torch
pip install --index-url https://download.pytorch.org/whl/cu121 torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1

 

 

111. TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

 (package) 해결 방법 : Python 3.10 이상으로 변경

 

 

112. ImportError: libcusparse.so.12: undefined symbol: __nvJitLinkComplete_12_4, version libnvJitLink.so.12

 (package) 해결 방법 : GPU 버전에 맞게 torch 새로 설치

 

# for example,
pip uninstall -y torch torchvision torchaudio
pip install --index-url https://download.pytorch.org/whl/cu121 torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1

 

 

113. ImportError: libXrender.so.1: cannot open shared object file: No such file or directory

 (package) 해결 방법 : sudo apt-get install libxrender1 (ref)

 

 

114. PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package.

(package) 문제 상황 : conda install -c psi4 psi4을 할 때 패키지가 꼬인 듯

(package) 해결 방법 : pip install "pydantic<2.0.0" 

 

 

115. AttributeError: module 'torch.utils._pytree' has no attribute 'register_pytree_node'

 (package) 해결 방법 : pip install -U "torch==2.2.*" "transformers==4.37.*"

 

 

116. ImportError: cannot import name 'is_flash_attn_available' from 'transformers.utils.import_utils'

 (package) 해결 방법 pip install -U "transformers==4.34.1"

레퍼런스 

 

 

117. ModuleNotFoundError: No module named 'pkg_resources'

 (package) 원인 : setuptools 82.0.0에서 pkg_resources가 아예 제거됨 

(package) 해결 방법 1. conda : conda install -y "setuptools<81" 

 (package) 해결 방법 2. 파이썬

 

import sys, subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall", "setuptools<81"])

 

 

118. AttributeError: module 'numpy' has no attribute 'bool'.

 (package) 해결 방법 : pip uninstall -y numpy; pip install "numpy==1.23.5"

 

입력: 2025.01.21 23:29