Python Major Troubleshooting [61-80]
Recommended Post : 【Python】 Python Table of Contents
61. ImportError: libGL.so.1: cannot open shared object file: No such file or directory
⑴ (package) Problem : Issue occurs when importing cv2.
⑵ (package) Solution 1: For Ubuntu/Debian.
sudo apt-get update
sudo apt-get install -y libgl1-mesa-glx
pip uninstall opencv-python
pip install opencv-python
⑶ (package) Solution 2: For CentOS/Fedora.
sudo yum update
sudo yum install -y mesa-libGL
pip uninstall opencv-python
pip install opencv-python
62. AttributeError: module ‘keras.optimizers’ has no attribute ‘Adam’
⑴ (grammar) Solution : Insert the following code into the problematic function.
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
experimental_run_tf_function=False
⑵ (grammar) Note : Some code uses optimizers.adam
instead of optimizers.Adam
. Be aware that this can cause errors depending on the environment, but not always.
63. ImportError: cannot import name ‘__author__’ from ‘scanpy._metadata’ (/opt/conda/lib/python3.8/site-packages/scanpy/_metadata.py)
⑴ (package) Solution : You need to install scanpy=1.9.0
at first.
⑵ Regarded as a Kubflow-specific issue
64. Error reading image file /home/jovyan/_janus/microbiome/Region1_colon_d0_rotated.tif while estimating memory requirements: TIFF has unsupported color type - must be 8-bit per component RGB or 8/16-bit gray
⑴ (grammar) Issue : The file Region1_colon_d0_rotated.tif being a high-depth .tif file is the problem.
⑵ (grammar) Solution : Convert to 8-bit .tiff file at https://online-image-converter.com/.
65. java.lang.IllegalArgumentException: Unsupported class file major version 55
⑴ (package) Solution : Upgrade or downgrade the Java version on Linux (ref).
66. java.lang.IllegalArgumentException: Unsupported class file major version 55
⑴ (package) Issue: Error occurred in cnv.io.genomic_position_from_gtf('./gencode.v19.annotation.gtf.gz', adata=adata)
⑵ (package) Solution: Change the polars version to less than 0.17, such as pip install polars==0.16.1
(ref)
Incompatible with polars version >=0.17 due to usage of polars.toggle_string_cache.
67. ModuleNotFoundError: No module named ‘ot’
⑴ (package) solution : pip install POT
68. AttributeError: module ‘scvi’ has no attribute ‘model’
⑴ (package) solution : pip install scvi-tools
69. JVMNotFoundException: No JVM shared library file (libjvm.so) found. Try setting up the JAVA_HOME environment variable properly.
⑴ (package) solution 1. sudo apt install default-jre
⑵ (package) solution 2. sudo apt install openjdk-8-jre-headless
⑶ (package) solution 3. sudo apt install openjdk-11-jre-headless
⑷ (package) solution 4. sudo apt install openjdk-13-jre-headless
⑸ (package) solution 5. sudo apt install openjdk-16-jre-headless
⑹ (package) solution 6. sudo apt install openjdk-17-jre-headless
⑺ (package) solution 7. manual installation
① Install Java from Official Oracle website : Use
wget
.
②
export JAVA_HOME=/path/to/java/jdk
③
export PATH=$PATH:$JAVA_HOME/bin
④
echo $JAVA_HOME # verification
⑤
java -version # verification
⑥ restart and re-run
70. ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 316 and the array at index 1 has size 1
⑴ (grammar) Problem Situation: An error is called when the two arguments for calculating the correlation coefficient do not have the same shape
.
⑵ (grammar) Solution: Generally, the issue can be resolved by treating both arguments with .flatten()
to make them one-dimensional and then calculating the correlation coefficient. However, if one of them is in Matrix form, flattening it with .flatten()
won’t work, so in this case, you need to change it to np.array
and then calculate the correlation coefficient.
from scipy.stats import spearmanr
bulk_like_merged_adata_1 = np.sum(merged_adata_1_common.X, axis=0)
bulk_like_merged_adata_1 = np.array(bulk_like_merged_adata_1)
bulk_like_merged_adata_1 = bulk_like_merged_adata_1[0]
bulk_expression = np.sum(adata_common.X, axis=0)
bulk_expression = np.array(bulk_expression)
bulk_expression = bulk_expression[0]
# Calculate the Spearman correlation
corr, _ = spearmanr(bulk_like_merged_adata_1, bulk_expression_vector)
71. Cases where the font size does not change in scanpy.pl.spatial
⑴ (grammar) Problem Situation: While using plt.rc('font', size = 10)
changes the font size in scanpy plots uniformly, there are cases where this does not happen.
⑵ (grammar) Solution: Remove the following code if present (to prevent conflict between plt and scanpy settings).
sc.set_figure_params(scanpy=True, fontsize=14)
sc.set_figure_params(facecolor="white", figsize=(8, 8))
sc.settings.verbosity = 3
# verbosity: errors (0), warnings (1), info (2), hints (3)
72. ImportError: cannot import name ‘url_decode_stream’ from ‘werkzeug.urls’
⑴ (package) Solution (ref)
# My original requirements.txt
bcrypt==4.0.1
blinker==1.6.2
click==8.1.7
dnspython==2.4.2
email-validator==2.0.0.post2
Flask==3.0.0
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.2.0
greenlet==2.0.2
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
SQLAlchemy==2.0.21
typing_extensions==4.8.0
Werkzeug==3.0.0
WTForms==3.0.1
# My modified requirements.txt
bcrypt==4.0.1
blinker==1.6.2
click==8.1.7
dnspython==2.4.2
email-validator==2.0.0.post2
Flask==2.3.0
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.2.1
greenlet==2.0.2
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
SQLAlchemy==2.0.21
typing_extensions==4.8.0
Werkzeug==2.3.0
WTForms==3.0.1
73. TypeError: ‘module’ object is not callable
⑴ (grammar) Solution
# before
import glob
mouse_tissue_files = glob("./data/droplet/*")
# after
import glob
# Correctly use glob to list files matching the pattern
mouse_tissue_files = glob.glob("./data/droplet/*")
74. error: urllib3 2.2.1 is installed but urllib3<1.27,>=1.25.4 is required by {‘botocore’}
⑴ (package) Solution (ref)
pip install urllib3==1.25.11
75. UFuncTypeError: ufunc ‘add’ did not contain a loop with signature matching types (dtype(‘<U32’), dtype(‘<U32’)) -> dtype(‘<U32’)
⑴ (grammar) Cause: With the update of Space Ranger, tissue_positions.csv
is generated instead of tissue_positions_list.csv
, and due to the creation of an improper header (see below), an error occurs when viewing an AnnData with scanpy.pl.spatial
after using scanpy.read_visium
without reflecting this change.
# tissue_positions_list.csv (Previous)
ACGCCTGACACGCGCT-1,1,0,0,256,1780
TACCGATCCAACACTT-1,1,1,1,268,1760
...
# tissue_positions.csv (Newest)
barcode,in_tissue,array_row,array_col,pxl_row_in_fullres,pxl_col_in_fullres
ACGCCTGACACGCGCT-1,1,0,0,256,1780
TACCGATCCAACACTT-1,1,1,1,268,1760
⑵ (grammar) Solution: Rename tissue_positions.csv
to tissue_positions_list.csv
and remove the header as in the previous version.
76. ImportError: cannot import name ‘optim’ from ‘flax’
⑴ (package) Solution (ref):
pip uninstall flax
pip install flax==0.5.3
77. OSError: Unable to open file: base_htrans.gin. Searched config paths: [’’, ‘third_party/py/meliad/transformer/configs’].
⑴ (grammar) Solution: Move the file ./meliad_lib/meliad/transformer/configs/base_htrans.gin
to one of the paths listed above.
⑵ (grammar) Reference
78. ModuleNotFoundError: No module named ‘gin’
⑴ (package) Solution: pip install gin-config (ref)
79. ImportError: Cannot load backend ‘TkAgg’ which requires the ‘tk’ interactive framework, as ‘headless’ is currently running
⑴ (grammar) Solution 1. import matplotlib
→ matplotlib.use('TKAgg')
→ import matplotlib.pyplot as plt
(ref)
⑵ (grammar) Solution 2. In my case, sometimes I delete the environment and reinstall it to run it again.
80. OSError: cannot open resource
⑴ (Grammar) Problem Context: An issue arises when specifying a custom font if the font file’s location cannot be found.
⑵ (Grammar) Solution (Reference): Use an alternative font as follows:
import os
import cv2
font_path = os.path.join(cv2.__path__[0], 'qt', 'fonts', 'DejaVuSans.ttf')
font = ImageFont.truetype(font_path, size=128)
Input: 2023.08.17 14:29
Revised: 2024.05.05 22:00