Tag Archives: python

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

Problem description

When running the code, an error is reported attributeerror: 'nonetype' object has no attribute 'asttype', as shown in the following figure:

Traceback (most recent call last):
  File "work/person_search-master/tools/demo.py", line 82, in <module>
    query_feat = net.inference(query_img, query_roi).view(-1, 1)
  File "/home/featurize/work/person_search-master/tools/../lib/models/network.py", line 178, in inference
    processed_img, scale = img_preprocessing(img)
  File "/home/featurize/work/person_search-master/tools/../lib/datasets/data_processing.py", line 49, in img_preprocessing
    processed_img = img.astype(np.float32)
AttributeError: 'NoneType' object has no attribute 'astype'

Solution:

According to the error message, the error is reported because the img is a ‘NoneType’ object, so the ‘astype’ property cannot be used.

In general, the above error occurs when the img does not exist, so

  • You need to make sure that the image exists in the appropriate path in the code.
  • You need to run the command python XXX.py in the correct directory to ensure that XXX.py searches for the image in the correct directory.

OMP Error: Initialising libiomp5md.dll [How to Solve]

Python Programmer OMP Error:

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

Solution: Add the following two lines of code to the beginning of the program.

import os
os.environ\['KMP\_DUPLICATE\_LIB\_OK'\]='True'

AttributeError str object has no attribut [How to Solve]

Error condition

# model_config = json.loads(model_config.decode(‘utf-8‘)) 
AttributeError: ‘str‘ object has no attribut

Because of tensorflow 2.1.0 support h5py< 3.0.0, while tensorflow will automatically install h5py 3.1.0 after installation
just run the following command:

pip install tensorflow h5py == 2.10.0

[Solved] hcitool Error: Set scan parameters failed: Operation not permitted

Set scan parameters failed: operation not allowed

The reason is that the function of hcitool tool is missing, and the lescan function needs to be supplemented

sudo apt-get install libcap2-bin
sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hcitool`
getcap !$

Execute again at this time

hcitool -i hci1 lescan

It is found that it can be scanned normally

Python Use sqlalchemy Error: pymssql.ProgrammingError: (102, b“Incorrect syntax near ‘(‘.DB-Lib error

As shown below, use create in Sqlalchemy_ Engine creates a database connection;

conn = create_engine('mssql+pymssql://' + dbuser + ':' + dbpassword + '@' + dbhost + '/' + database)

Then through pandas’ to_SQL method to the database,

df = pd.read_csv(filename, sep='|', header=0, quoting=3)

df.to_sql(name=filename + ty, con=conn, if_exists='replace', index=True)

Result error:

Traceback (most recent call last):
  File "src\pymssql.pyx", line 450, in pymssql.Cursor.execute
  File "src\_mssql.pyx", line 1064, in _mssql.MSSQLConnection.execute_query
  File "src\_mssql.pyx", line 1095, in _mssql.MSSQLConnection.execute_query
  File "src\_mssql.pyx", line 1228, in _mssql.MSSQLConnection.format_and_run_query
  File "src\_mssql.pyx", line 1639, in _mssql.check_cancel_and_raise
  File "src\_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (102, b"Incorrect syntax near '('.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

Supplementary error reporting exception information:

Traceback (most recent call last):
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1264, in _execute_context
    cursor, statement, parameters, context
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\default.py", line 587, in do_executemany
    cursor.executemany(statement, parameters)
  File "src\pymssql.pyx", line 476, in pymssql.Cursor.executemany
  File "src\pymssql.pyx", line 465, in pymssql.Cursor.execute
pymssql.ProgrammingError: (102, b"Incorrect syntax near '('.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\sql.py", line 948, in run_transaction
    yield tx
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\sql.py", line 641, in insert
    self._execute_insert(conn, keys, chunk_iter)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\sql.py", line 616, in _execute_insert
    conn.execute(self.insert_statement(), data)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1020, in execute
    return meth(self, multiparams, params)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\sql\elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1139, in _execute_clauseelement
    distilled_params,
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1324, in _execute_context
    e, statement, parameters, cursor, context
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1518, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\util\compat.py", line 178, in raise_
    raise exception
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1264, in _execute_context
    cursor, statement, parameters, context
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\default.py", line 587, in do_executemany
    cursor.executemany(statement, parameters)
  File "src\pymssql.pyx", line 476, in pymssql.Cursor.executemany
  File "src\pymssql.pyx", line 465, in pymssql.Cursor.execute
sqlalchemy.exc.ProgrammingError: (pymssql.ProgrammingError) (102, b"Incorrect syntax near '('.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

Mainly look at this line, which literally means [syntax error near ‘(‘):

_mssql.MSSQLDatabaseException: (102, b"Incorrect syntax near '('.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

Generally, we will first check whether the SQL is correct (or whether there are ‘special characters’ in the data), but strangely

When this program runs locally, it reads the same file and imports the same database table. Everything is normal!

At this time, it is suspected that the running environment on the local and remote servers is inconsistent, and the inspection found that it was not surprising; The version of Sqlalchemy on the remote is rather old, only 0.23.0

So I decided to upgrade and run again. Everything was normal~

[Solved] torchvision Error: UserWarning: Failed to load image Python extension: Could not find module

Tochvision error: userwarning: failed to load image Python extension: could not find module

One reason is that the version of torchvision is too high. It is suspected that the new version of torchvision has its own pot. At first, according to the official website

pip3 install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio===0.10.1+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html

After that, the error of image will be reported. You only need to reduce the version of torch vision. For example, you can enter it in your Anaconda prompt

conda activate ltorch # ltorch is the name of the virtual environment I created
pip install torchvision==0.10.1+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html

It was 0.11.2, but I reduced it to 0.10.1. Import without error:

Of course, you can change the version according to the following link

https://download.pytorch.org/whl/cu102/torch_stable.html

[Solved] wsgiref make_server Error: AssertionError: write() argument must be a bytes instance

from wsgiref.simple_server import make_server


def application(env, start_response):
    response_body = ["%s: %s" % (key, value) for key, value \
    in sorted(env.items())]
    response_body = '\n'.join(response_body)
    status = "200 ok"
    response_head = [("ContextType", "text/plain"), ("ContextLength",str(len(response_body)))]

    start_response(status, response_head)
    return [response_body]

httpd = make_server(
    "localhost",
    8000,
    application
)

httpd.handle_request()

An error is reported when accessing port 8000. The coding problem is modified in the

code

return [response_body]  
=>Modfied
return [response_body.encode('utf-8')]

Normal operation

Keras import package error: importerror: cannot import name ‘get_ config‘

ImportError: cannot import name ‘get_config’

Traceback (most recent call last):
  File "siameseNet.py", line 6, in <module>
    from keras.layers import Merge
  File "/usr/local/lib/python3.6/site-packages/keras/__init__.py", line 25, in <module>
    from keras import models
  File "/usr/local/lib/python3.6/site-packages/keras/models.py", line 19, in <module>
    from keras import backend
  File "/usr/local/lib/python3.6/site-packages/keras/backend.py", line 39, in <module>
    from tensorflow.python.eager.context import get_config
ImportError: cannot import name 'get_config'

Solution:

pip install keras == 2.1.0 --force-reinstall

[Solved] npm Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.

1. NPM error reporting

npm ERR! code 1
npm ERR! path D:\Workspaces\WebstormProjects\shop-ui\buyer\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (D:\Workspaces\WebstormProjects\shop-ui\buyer\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (D:\Workspaces\WebstormProjects\shop-ui\buyer\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at callback (D:\Workspaces\WebstormProjects\shop-ui\buyer\node_modules\graceful-fs\polyfills.js:299:20)
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\Workspaces\\WebstormProjects\\shop-ui\\buyer\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\Workspaces\WebstormProjects\shop-ui\buyer\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.13.2
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\Program Files\nodejs\node_cache\_logs\2022-01-28T09_54_16_535Z-debug.log

2. Solution
npm install --global --production windows-build-tools

[Solved] ubuntu Boot Error: /dev/nume0n1p2:clean

This is an error that cannot be reported in the graphical interface. Sometimes this problem occurs when the driver or program is updated.

Solution:
Ctrl + Alt + F2 enter the command line, enter the user name and password, and then enter the update library: sudo apt update

update kernel:
sudo apt upgrade

check for updates:
sudo apt install - f

delete old kernel:
sudo apt autoremove

Restart: reboot
Congratulations on your success!

How to Solve Python3.9 Install pycrypto Error

1. If VS2019 BuildTools and its corresponding VC++14 library are installed on the machine, go directly to C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include Copy the stdint.h file to the C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt directory in the directory (*14.29.30133 is the version number, which may be different depending on the version you installed) ;

2. Modify the C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\inttypes.h file: change the line 14

#include <stdint.h>

Change to

#include "stdint.h"

3. Execute in CMD

set CL=/FI"%VCINSTALLDIR%\\INCLUDE\\stdint.h" %CL%

4. Execute PIP3 install pycrypto or pip install pycrypto to install.

[How to Solve] Reason: Incompatible library version

Today’s respondent reported the following errors when testing the PIL package in Python:

Reason: Incompatible library version: _imaging.cpython-37m-darwin.so requires version 14.0.0 or later, but libjpeg.9.dylib provides version 12.0.0

By analyzing the error message, we can see that it is caused by the version incompatibility between libraries, because the PIL library is old and only supports python2.7, which may lead to this problem. So we think about how to solve it.

Solution

First, consider reloading the library. The basic environment of this environment is Python 3.7. Therefore, enter the code on the command line, delete the library first, and then reinstall it.

conda uninstall pillow
conda install pillow

Finally, the test re imports the library successfully and outputs the size of the picture

Successfully solve the problem!