Category Archives: Python

How to Solve M1 chip import numpy Error

Error report of M1 chip import numpy

Environmental installation method:

miniforge – python3. 9 numpy 1.21.1

Operation error:

## terminal/pycharm error
import numpy
import pandas 

Error Messages:
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

At the same time, the python version and numpy version are given, and many files in the miniforge folder no such file are mentioned repeatedly

Solution:

conda install openblas

Import again works normally

How to Solve Python picamera and raspistill error

1. Turn on raspberry pie settings

sudo raspi-config

2. Select the third interface options

3. Turn all options on, and then restart raspberry pie

4.vcgencmd get_camera

The values change to 1, which can not only detect the input, but also identify the device

5. You can execute raspistill and run the python picamera program

For example: raspistill -o /home/pi/Desktop/first.jpg

How to Solve cv2.applyColorMap Error

You need to convert the image to 255 and uint8, and then turn back.

        real_image = cv2.cvtColor(real_image,cv2.COLOR_GRAY2RGB)
        real_image = cv2.resize(real_image,(256,256))
        real_image *= 255
        real_image = real_image.astype(np.uint8)
        real_image = cv2.applyColorMap(real_image, cv2.COLORMAP_HOT)
        real_image = np.asarray(real_image/255, dtype=np.float32)

[Solved] yolo Error: IndexError: invalid index to scalar variable.

code:

yolo_layers = [layers[i[0] - 1] for i in network.getUnconnectedOutLayers()]

report errors:

Traceback (most recent call last):
  File "Run.py", line 201, in <module>
    main()
  File "Run.py", line 137, in main
    detections = yolo.detect(yolo_img)
  File "code/3D-BoundingBox-master/yolo/yolo.py", line 34, in detect
    ln = [ln[i[0] - 1] for i in self.net.getUnconnectedOutLayers()]
  File "code/3D-BoundingBox-master/yolo/yolo.py", line 34, in <listcomp>
    ln = [ln[i[0] - 1] for i in self.net.getUnconnectedOutLayers()]
IndexError: invalid index to scalar variable.

Reason:
different opencv versions cause different output formats

Solution:

yolo_layers = [layers[i - 1] for i in network.getUnconnectedOutLayers()]

Reference:
https://stackoverflow.com/questions/69834335/loading-yolo-invalid-index-to-scalar-variable

[Solved] Python Pandas Read Error: OSError: initializing from file failed

Problem Description:

error when loading CSV format data in pandas

B = pd.read_csv("C:/Users/hp/Desktop/Hands-On Data Analysis/Unit 1 Project Collection/train.csv")
B.head(3)

report errors:

OSError: Initializing from file failed

Cause analysis:

When calling the read_csv() method of pandas, the C engine is used as the parser engine by default, and when the file name contains Chinese, using the C engine will be wrong in some cases.


Solution:

Specify the engine as Python when calling the read_csv() method

B = pd.read_csv("C:/Users/hp/Desktop/Hands-On-Data-Analysis/Unit-1-Project-Collection/train.csv",engine='python')
B.head(3)

[Solved] original_keras_version = f.attrs[‘keras_version‘].decode(‘utf8‘)

windows system:
original_keras_version = f.attrs[‘keras_version’].decode(‘utf8’)
1. error:

load_weights_from_hdf5_group
    original_keras_version = f.attrs['keras_version'].decode('utf8')

AttributeError: 'str' object has no attribute 'decode'

2. Cause analysis

When installing tensorflow, the default installed h5py is 3.1.0, and an error is reported because the TF you installed does not support an excessively high version of h5py

3. Solutions

1. Uninstall h5py3 Version 1.0, installing h5py2.0 Version 10.0.2. Restart the compiler

pip install h5py==2.10.0

[nltk_data] Error loading wordnet_ic: HTTP Error 404: Not Found

Error loading XXXX: http Error 404: not found
XXXX can be WordNet or nltk_ Any package in data

Solution:

    1. 1. local download

    Find the package you need → copy the corresponding address → download → unzip to “your nltk_data path \nltk_data\corpora”
    For example: “wordnet_ic” “https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/ wordnet_ic.zip”

    <package id="wordnet_ic" 
    name="WordNet-InfoContent" 
    version="3.0" 
    webpage="http://wn-similarity.sourceforge.net" 
    unzip="1" 
    unzipped_size="34220359" 
    size="12056682" 
    checksum="25f0185b31693fa11ea898e4feda528c" 
    subdir="corpora" 
    url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/wordnet_ic.zip" />
    

    2. Unzip directly
    when we install nltk, XXX.Zip will be included in “your nltk_data path\nltk_data\corpora”. We can first search to see if the package you need exists in the corpora directory. If so, just unzip it directly. Easy.

[Solved] Pytorch call tensorboard error: AttributeError: module ‘tensorflow’ has no attribute ‘gfile’

Problem description

An error occurs when executing the following command:

from torch.utils.tensorboard import SummaryWriter

tb_writer = SummaryWriter(osp.join(opt.savepath, "logdir"))

Error content:

AttributeError: module 'tensorflow._api.v1.io' has no attribute 'gfile'

Problem analysis

The root cause of this problem is that pytorch has adjusted tensorflow. Finally, tensorflow reports an error. The new version of tensorflow is incompatible with the old version.

After checking, my pytorch version is 1.6, tensorboard version is 1.15.0, and tensorflow version is 1.12.0

Problem-solving:

Upgrade the tensorflow version to version 2.0. Executing the following command will automatically upgrade the tensorflow version and tensorboard version:

pip install tensorflow==2.0

End.

[Solved] RuntimeError: ProcessGroupNCCL is only supported with GPUs, no GPUs found

GPU Error: RuntimeError: ProcessGroupNCCL is only supported with GPUs, no GPUs found!

pg = ProcessGroupNCCL(prefix_store, rank, world_size, pg_options)
RuntimeError: ProcessGroupNCCL is only supported with GPUs, no GPUs found!

At first, this mistake made me wonder if this GPU was useless, – – |, But the little partners in the lab are sure that GPU is OK! Then I started the bug troubleshooting journey

At this time, when viewing the command line, it finally shows its feet. It is estimated that there is a problem with pytorch, which is harmful!

>>> import torch
>>> print(torch.cuda.is_available())
/home/xutianjiao/anaconda3/envs/py36/lib/python3.6/site-packages/torch/cuda/__init__.py:80: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 9020). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at  ../c10/cuda/CUDAFunctions.cpp:112.)
  return torch._C._cuda_getDeviceCount() > 0
False
>>> print(torch.cuda.get_device_name(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xutianjiao/anaconda3/envs/py36/lib/python3.6/site-packages/torch/cuda/__init__.py", line 326, in get_device_name
    return get_device_properties(device).name
  File "/home/xutianjiao/anaconda3/envs/py36/lib/python3.6/site-packages/torch/cuda/__init__.py", line 356, in get_device_properties
    _lazy_init()  # will define _get_device_properties
  File "/home/xutianjiao/anaconda3/envs/py36/lib/python3.6/site-packages/torch/cuda/__init__.py", line 214, in _lazy_init
    torch._C._cuda_init()
RuntimeError: The NVIDIA driver on your system is too old (found version 9020). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver.

After checking this error, it shows that the versions of CUDA and torch do not match.

Check the version of pytorch, 1.10 +. OK, try installing a lower version of torch!

pip install torch==1.7.0

be accomplished!