Tag Archives: python

[Solved] Python import Error: pip –upgrade Error: ERROR: Cannot uninstall ‘dnspython‘. It is a distutils installed

Background:
today we use package to install the module dnspython

[root@makel ~] wget http://www.dnspython.org/kits/1.9.4/dnspython-1.9.4.tar.gz
[root@makel ~] tar -xvf dnspython-1.9.4.tar.gz
[root@makel ~] cd dnspython-1.9.4/
[root@makel dnspython-1.9.4] python3 setup.py install

Solution process
1. Enter Python and import reports an error (problem found)

[root@makel ~] python3
Python 3.8.5 (default, Nov  7 2021, 21:47:38) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns.resolver
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python3/lib/python3.8/site-packages/dns/resolver.py", line 26, in <module>
    import dns.message
  File "/usr/local/python3/lib/python3.8/site-packages/dns/message.py", line 175
    return '<DNS message, ID ' + `self.id` + '>'
                                 ^
SyntaxError: invalid syntax

2. Try upgrading (– upgrade) and find that it still can’t be installed

[root@makel ~] pip3 install dnspython --upgrade
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: dnspython in /usr/local/python3/lib/python3.8/site-packages (1.9.4)
Collecting dnspython
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f5/2d/ae9e172b4e5e72fa4b3cfc2517f38b602cc9ba31355f9669c502b4e9c458/dnspython-2.1.0-py3-none-any.whl (241 kB)
     |████████████████████████████████| 241 kB 898 kB/s            
Installing collected packages: dnspython
  Attempting uninstall: dnspython
    Found existing installation: dnspython 1.9.4
ERROR: Cannot uninstall 'dnspython'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

3. A new error occurred while attempting to uninstall

[root@makel ~] pip3 uninstall dnspython
Found existing installation: dnspython 1.9.4
ERROR: Cannot uninstall 'dnspython'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

4. If the command cannot be unloaded, delete the file manually

[root@makel ~] cd /usr/local/python3  #Go to the directory where python is installed
[root@makel python3] find ./-name "*package*" #Fuzzy search package
./lib/python3.8/site-packages
./lib/python3.8/site-packages/setuptools/package_index.py
./lib/python3.8/site-packages/setuptools/__pycache__/package_index.cpython-38.pyc
./lib/python3.8/site-packages/setuptools/__pycache__/package_index.cpython-38.opt-1.pyc
......
[root@makel python3] cd lib/python3.8/site-packages/ #Find site-packages from the above results and go to this directory
[root@makel site-packages] ll  
total 96
drwxr-xr-x. 4 root root  4096 Nov 16 17:18 dns
-rw-r--r--. 1 root root  1277 Nov  9 22:31 dnspython-1.9.4-py3.8.egg-info
....
[root@makel site-packages] rm -rf dnspython-1.9.4-py3.8.egg-info   #Delete all files containing the module name

5. Reinstall and import successfully after installation

[root@makel site-packages] pip3 install dnspython #reinstall
[root@makel site-packages] python3
Python 3.8.5 (default, Nov  7 2021, 21:47:38) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns.resolver
>>> exit

[Solved] Training yolov5 Error: attributeerror: can get attribute sppf on Module

Problem Description:

There was a problem running the yolov5-train.py file:

Attributeerror: cant get attribute sppf on module models.common… (followed by file path)

Solution:

1. Double click to open the common.py file:

2. Add code:

import warnings

class SPPF(nn.Module):
    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))
        super().__init__()
        c_ = c1 // 2  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)

    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))


Copy and paste it directly into the common.py file.
Tips: Put import warnings on it!

Pytorch Error: runtimeerror: expected scalar type double but found float

The reason for this problem may be that the data type of tensor is wrong, it may be the wrong type of input X in the backpropagation, or the wrong data type in the training and testing process. If it is the backpropagation process, it depends on which layer of neural network has the problem, and add x = x.to (torch. Float32) in front of which layer, For example, this problem occurs in the first layer of neural network. For example, this problem occurs in the first layer of convolution. The solution is as follows:

If this problem occurs in the training or test model, the solution is as follows:

It is also possible that the type of labels is wrong during training or testing. The solutions are as follows:

ERROR: Adobe Flashplayer or HTML5 Browser with WebGL or CSS3D support requ

Error appears on the pyqt5 qwebengine VR interface: Adobe flashplayer or HTML5 browser with webgl or css3d support requ

The following sentences can prevent the interface from flickering. If you add more, the image above will appear. As long as you leave other comments and the last sentence, you can solve the interface flickering and play VR video.

from PyQt5.QtCore import *
from PyQt5.QtGui import *   

# QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL,True)
# QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL, True)
# QGuiApplication.setAttribute(Qt.AA_UseSoftwareOpenGL, True)
# QApplication.setAttribute(Qt.AA_UseSoftwareOpenGL, True)

QCoreApplication.setAttribute(Qt.AA_UseOpenGLES, True)

AttributeError: ‘WebDriver‘ object has no attribute ‘w3c‘

Problems encountered in the process of automatic testing of mobile terminal with Python + appnium.

Reason: I reported an error in selenium 3.3.1. After uninstalling selenium, I reinstalled selenium 4.0.0 (installed by default and the latest version). I ran it again and the problem was solved. Only the positioning mode needs to be changed to the latest, otherwise there will be a warning.

The new positioning method of mobile terminal is as follows:

from appium.webdriver.common.mobileby import MobileBy

driver.find_element(MobileBy.ID, "com.tencent.mm:id/hej").click()

[Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘

Problem: in Python, when adding an element to a list, an error is reported attributeerror: ‘nonetype’ object has no attribute ‘append’
my code at that time was:

loss=[]
loss=loss.append(0.1)

Solution: change the code to the below

oss=[]
loss.append(0.1)

The append in the list can directly update the list of added elements without assignment

RuntimeError: Non RGB images are not supported [How to Fix]

Another version problem… I ran into it all. The version of
torchvision is too low, io.read_ Image does not support grayscale images. You can only read three channel color images…

segmentation = mask_to_rle(torchvision.io.read_image(os.path.join(self.root, m['mask']))[0] == 255)

current version

torchvision==0.8.2

Upgraded version

torchvision==0.9.0

Problem solved, yep! Of course, it is possible to solve the problem without upgrading torchvision. You can first convert the gray image into a three channel image, and you can try
(it’s also a reminder. Pay attention to the matching of torch versions)

raise HTTPError(req.full_url, code, msg, hdrs, fp)urllib.error.HTTPError: HTTP Error 404: Not Found

import requests
url=['www....','www.....',...]
for i in range(0,len(url)):
     linkhtml = requests.get(url[i])

The crawler reported the following error:


  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 247, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 640, in http_response
    response = self.parent.error(
  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Users\lenovo7\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Refer to an article on stack overflow

Python: urllib.error.HTTPError: HTTP Error 404: Not Found – Stack Overflow

In the crawler scenario, the original link may not open. Naturally, it will prompt HTTP Error 404. What you need to do is skip this link and then crawl to the following page

Correction code

import requests
url=['www....','www.....',...]
for i in range(0,len(url)):
    try:
        linkhtml = requests.get(url[i])
    except:
        pass