Tag Archives: python

TensorFlow Install Error: Could not load dynamic library ‘*****.dll‘; dlerror: ********.dll not found

After the installation of tensorflow2. X is successful, after running the following code:

tf.config.list_physical_devices('GPU')

There are always the following situations: (Note: there are usually multiple, only two here are shown here)

Could not load dynamic library ‘cublas64_ 10.dll’; dlerror: cublas64_ 10.dll not found

Could not load dynamic library ‘cudnn64_ 7.dll’; dlerror: cudnn64_ 7.dll not found

Solution:

Download the corresponding DLL file and put it into the folder C: Windows: system32.

The problem was solved successfully Pro test (valid)

So the key to the problem, where to download these DLL files, rest assured, this article will provide you with all the required DLL files.

Crawler overtime error socket.timeout: timed out/NameError: name ‘socket‘ is not defined

Question 1: socket. Timeout: timed out

Source code:

import urllib.request#Get a get request

import urllib.parse #Get a pos request

import urllib.error
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'}
data1 = urllib.request.Request("http://httpbin.org/post", headers=headers)

response = urllib.request.Request("http://httpbin.org/get", headers=headers)
response1 = urllib.request.urlopen(response, timeout=0.01)
# response1 = urllib.request.urlopen(response)
print(response1.read().decode("utf-8"))

Abnormal operation result:

Traceback (most recent call last):
  File "D:\PycharmProjects\pythonProject\douban\test1\testurllib.py", line 53, in <module>
    response1 = urllib.request.urlopen(response, timeout=0.01)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1375, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1350, in do_open
    r = h.getresponse()
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1345, in getresponse
    response.begin()
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\socket.py", line 704, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

Process finished with exit code 1

Question 2: NameError: name ‘socket’ is not defined

Source code:


import urllib.request#Get a get request

import urllib.parse #Get a pos request
import urllib.error
try:
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'}
    # data1 = urllib.request.Request("http://httpbin.org/post", headers=headers)

    response = urllib.request.Request("http://httpbin.org/get", headers=headers)
    response1 = urllib.request.urlopen(response, timeout=0.01)
    print(response1.read().decode("utf-8"))

except socket.timeout as e:
# except Exceptio as e:
# except urllib.error.URLError as e:##error socket.timeout: timed out
    print("time out!")

Abnormal operation result:

Traceback (most recent call last):
  File "D:\PycharmProjects\pythonProject\douban\test1\temp.py", line 19, in <module>
    response1 = urllib.request.urlopen(response, timeout=0.01)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1375, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1350, in do_open
    r = h.getresponse()
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1345, in getresponse
    response.begin()
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\lord\AppData\Local\Programs\Python\Python39\lib\socket.py", line 704, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\PycharmProjects\pythonProject\douban\test1\temp.py", line 22, in <module>
    except socket.timeout as e:
NameError: name 'socket' is not defined

Solution:

Refer to the network resources, delete and install Python again, and still report an error.

By introducing socket library, problem one and problem two are solved.

import socket    ##Introducing the socket library

Correct code:

import socket ## Introduce the socket library

import urllib.request # Get a get request

import urllib.parse # Get a pos request
import urllib.error

try:
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'}
    # data1 = urllib.request.Request("http://httpbin.org/post", headers=headers)

    response = urllib.request.Request("http://httpbin.org/get", headers=headers)
    response1 = urllib.request.urlopen(response, timeout=0.01)
    print(response1.read().decode("utf-8"))

except socket.timeout as e:
# except Exceptio as e:##normal
# except urllib.error.URLError as e:## error socket.timeout: timed out
    print("time out!")

Results of correct operation:

time out!

Process finished with exit code 0

Conclusion:

If try/except statement is not used, the program will report error a
a try/except statement has been added. It should be noted that the exception name of except should correspond to a. the error “NameError: name ‘socket’ is not defined” is reported here because the socket library is not imported.

[Solved] YOLOv5 Model training error: TypeError: new(): invalid data type ‘str’

After modifying the anchors in yolov5s.yaml, I made an error report when I retrained. After carefully looking at the numbers in “[]”, I found that the reason was as follows:
the number in “[]” 👇 Here is the original configuration file

👇 This is my revised version of

because of the lack of “,” leading to continuous error reporting, we must be more careful and encourage each other

[Solved] Tensorflow cuda Error: Could not load dynamic library ‘libcudart.so.11.0‘; dlerror: libcudart.so.11.0:

Dlerror: libcudart. So. 11.0: problem solving

First find your computer path

/usr/local/cuda/lib64

Check your CUDA version
. According to the above figure, I find that my computer’s CUDA version is 10.0, so I will report an error at runtime. At this time, there are two solutions.

Scheme 1

If you force the CUDA environment of the local computer to be the running CUDA environment, there may be problems, which I haven’t tried.

cd /usr/local/cuda/lib64/
sudo ln -sf libcudart.so.10.0 libcudart.so.11.0

Scheme 2

Installing dynamic CUDA environment in CONDA environment

conda install tensorflow-gpu cudatoolkit=11.0

Failed to establish a new connection: [winerror 10048] in the requests thread pool, the interface is called circularly to get the datagram error

To solve the problem that in the requests thread pool, loop call the interface to get data and report an error failed to establish a new connection: [winerror 10048] generally, each socket address (Protocol/network address/port) is only allowed to be used once

My code first

import json
import csv
from threadpool import ThreadPool
import threadpool
from threadpool import makeRequests
import time
import random
with open('all_balance.csv','r') as f:
    list1 = csv.reader(f)
    list1 = list(list1)
def load_data(name):
    while True:
        Payload = {
          "id": 0,
          "jsonrpc": "2.0",
          "method": "Filecoin.StateGetActor",
          "params":
          [name[0],[{'/': 'bafy2bzaceazzbdegiso5c4tsjipxjmdabpk5uamj6khzhuwycb4bjeafbhaeo'}, {'/': 'bafy2bzacea4pnuzojwownzajhjdlqitt4wodbvgmhhfc4dujqdkjz3lgl6sac'}, {'/': 'bafy2bzacecjsgkjrcg6bejnqbvm2lktrhxpiazrqwfppueijfzte2bf2kwx42'}, {'/': 'bafy2bzaceaeglquy7h5i6tobxqikaqh2onzvhdjzdhpdneo47grs3qdvvbzc6'}, {'/': 'bafy2bzacea2knbqirjgw7rsfrydo6gfams6wnbpfdrvxhasuo6obqipn4zoco'}, {'/': 'bafy2bzacecmfiu5w7gpuhvdudqpd4qvwng2wokoj6mqydismrujcobgtcunxe'}, {'/': 'bafy2bzacec5mzv2jqqd7k2ripfddlsjv5k2eq52tihjpbtjok37p5hkxep2za'}, {'/': 'bafy2bzacedqyr6oufui2plsbykvevrioa6ukuviyb4i5iz5mq34xxq3gzlz32'}, {'/': 'bafy2bzacecled7zvadjt2jjn354pfhyga22apgqeh5c3ig3vv62tqb6rujsxk'}, {'/': 'bafy2bzacecfyxsfr445b6cvlxnl2p53twzfw4fjqy67bg6nioopb5apa6zb62'}, {'/': 'bafy2bzacech6xyahzbhyyjjd747cyzpllgx4abksncyidxpuxg7hsm2gydxw6'}, {'/': 'bafy2bzaceaisnevf7cpht6cmiwg2l63cqxi5jqyrinjsmdqyvax3delxnj4gg'}]]}
        headers = {"Content-Type": "application/json"}`

        respon = requests.post('http://********:1248/rpc/v0',headers=headers, data=json.dumps(Payload))

        if respon.status_code == 200:
            if respon.json().get('result'):
                print(name[0],int(respon.json()['result']['Balance'])/10**18)
                with open('all_balance_6_24.csv', 'a', encoding='utf-8', newline='') as f:
                    writer = csv.writer(f)
                    writer.writerow([name[0], int(respon.json()['result']['Balance'])/10**18])
                return
        else:
            print(respon.status_code)
            print(respon.text)
            time.sleep(20)
tasks = threadpool.makeRequests(load_data, [list1[i] for i in range(1, 488013)])
pool = threadpool.ThreadPool(100)
for task in tasks:
    pool.putRequest(task)
pool.wait()

Error code

Traceback (most recent call last):
  File "E:\project\chain\lib\site-packages\threadpool.py", line 158, in run
    result = request.callable(*request.args, **request.kwds)
  File "E:\project\chain\chain_main_get_state.py", line 22, in load_data
    respon = requests.post('http://10.0.6.22:1248/rpc/v0',headers=headers, data=json.dumps(Payload))
  File "E:\project\chain\lib\site-packages\requests\api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "E:\project\chain\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "E:\project\chain\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "E:\project\chain\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "E:\project\chain\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.0.6.22', port=1248): Max retries exceeded with url: /rpc/v0 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000028BAE472C40>: Failed to establish a new connection: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。'))

Because it’s multithreading, the so-called shutdown of Python process is not the way I want. Finally, I find an effective way to test the effectiveness:

use regedit command to access HKEY_ LOCAL_ Machine/system/currentcontrolset/services/TCPIP/parameters registry subkey and create a new reg named tcptimedwaitdelay_ DWORD value. Set this value to decimal 30, which is hexadecimal 0x0000001E. This value sets the wait time to 30 seconds</ Code>
access HKEY with regedit command_ LOCAL_ Machine/system/currentcontrolset/services/TCPIP/parameters registry subkey and create a new reg named maxuserport_ DWORD value. Stop and restart the system. Default: no recommendation: at least 32768 decimal

When I called the interface, using the command-line tool netstat – N, I found that nearly 4000 connections to the IP address of the target computer running the interface were in time_ In wait state, you can increase the default maxuserport setting and decrease the tcptimedwaitdelay setting at the same time, so that the client anonymous port will not be exhausted. For example, you can set maxuserport to 20000 and tcptimedwaitdelay to 30. A lower tcptimedwaitdelay setting means that the socket is in time_ The waiting time in wait state is shorter. A higher maxuserport setting means that you can put more sockets in time_ Wait status

[Solved] UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 3-9: ordinal not in range(128)

linux django UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 36-45: ordinal not in range(128)
error:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 36-45: ordinal not in range(128)

Solution:

vi ~/.bashrc
export LC_ALL=C.UTF-8
source ~/.bashrc

[Solved] TypeError: xx takes 1 positional argument but 4 were given

The problem is that there is an error when the thread transmits data. For example, the following sentence will report an error when it runs

threading.Thread(target=intent, args=([1, 2, 3, 4])).start()

The solution is to add a comma to the last face, as follows

    threading.Thread(target=intent, args=([1, 2, 3, 4],)).start()
    # or
    threading.Thread(target=intent, args=[[1, 2, 3, 4], ]).start()

How to Solve Turtle_tf Error in ROS

Software configuration

Operating system: Ubuntu 16.04
ROS version: kinetic
Python version: python2.7, python3.5, python3.8

Function package and routine

Refer to “ROS robot development and practice” section 4.2.3 using turtle simulator routine turtle_ TF, execute the command:

roslaunch turtle_tf turtle_tf_demo.launch

report errors

Traceback (most recent call last):
   File "/opt/ros/kinetic/lib/turtle_tf/turtle_tf_broadcaster.py", line 37, in <module>
        import tf   
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf/__init__.py", line 28, in <module>
        from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module>     
        from tf2_py import *   
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module>     
        from ._tf2 import * ImportError: dynamic module does not define module export function (PyInit__tf2) Traceback (most recent call last):   
   File "/opt/ros/kinetic/lib/turtle_tf/turtle_tf_broadcaster.py", line 37, in <module>     
        import tf   
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf/__init__.py", line 28, in <module>    
        from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException   
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module>     
        from tf2_py import *  
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module>     
        from ._tf2 import * ImportError: dynamic module does not define module export function (PyInit__tf2) 
Traceback (most recent call last):   
   File "/opt/ros/kinetic/lib/turtle_tf/turtle_tf_listener.py", line 37, in <module>     
        import tf   
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf/__init__.py", line 28, in <module>     
        from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException  
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module>     
        from tf2_py import *   
   File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module>     
        from ._tf2 import * ImportError: dynamic module does not define module export function (PyInit__tf2) 

find by hard and thorough search

At the beginning, try the methods mentioned on the Internet, such as modifying the python version and soft link, and input on the terminal:

python --version

After getting python2.7, the running routine still reports an error, so I want to find the reason according to the error

Find the error report file from the first line of the error report:

/opt/ros/kinetic/lib/turtle_tf/turtle_tf_broadcaster.py

Turn on Turbo_ tf_ After editing the broadcast.py file, it is found that the first line of the file states:

#!/usr/bin/env python

Input in the terminal:

/usr/bin/env python

It shows the python version pointed by the python variable in the environment variable, which is different from the routine’s requirement of python2.7.

Problem solving: modify Python in environment variables

//Modify the priority of different python versions
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

//Manual priority selection
sudo update-alternatives --config python

*Remember to input “/ usr/bin/env Python” in the terminal to check whether the modification is successful.

After the modification is successful, run the routine again to see two little turtles. The little turtle at the bottom moves towards the little turtle at the center.

How to solve the problem of error reporting in the introduction of Python Django no module name ‘Django. Utils. Six’

Today, when learning Django framework, I wrote the following command:

from django.utils.six import BytesIO

After that, an error is reported as follows:

I looked up the relevant documents, various, did not come to the point.

In fact, the root of this problem is very easy to understand: there may be no such file as six. Py under the path of Django/utils /!!

Taking this machine as an example, I first checked the following path. There is no file “six. Py”.

Next, I chose to use the command line:

pip install six

But the previous command still runs and reports an error, although the six. Py has been downloaded.

At this time, you need to go to your PIP folder and find the file “six. Py”

Then copy the file and paste it under the path of Django/utils

At this point, rerun the command

from django.utils.six import BytesIO

After running successfully, no error is reported

It’s done!!

Run Python file for the first time with eclipse / pydev: “UTF-8 ‘codec can’t decode byte 0xc4 in position

Today, after successfully installing pydev with eclipse, try to run it. Since the creation date of the file contains Chinese characters by default, the Unicode error as shown in the figure appears after running  

Online solutions to find two, and then I have derived a third (focus). The method is as follows

Method 1: File & gt& gt; Properties>& gt; Text file encoding>& gt; O ther:utf-8

After completing the above steps, there will be garbled code, delete and re-enter Chinese characters can be normal operation!

 
Method 2: edit & gt& gt; Set Encoding  & gt;& gt; O ther:utf-8 (the same as the method one by one, there will be garbled codes. Just delete them and input them again.)

 
Method 3: right click on the python project/Package & gt& gt; Properties and method 1 are similar operations

The first two methods are both temporary but not permanent, that is, they can only solve the Unicode error of the current file, and a new Python file will still have a Unicode error; After using method 3, as long as the file is created under the project, its encoding is UTF-8, and there will be no Unicode   It solves the problem from the root.

Method 3: discovery process

In method 1, in properties & gt& gt; In run/debug setting, I found that the current code setting object is only the current file, so I thought of giving it to the whole python   Project to set the encoding, so right-click the mouse on the project, found the projperties option, according to the operation of method 1 to try, successfully solved the Unicode problem   So there is method 3