Category Archives: Python

Flask Database Migration Error: ERROR [flask_migrate] Error: Can‘t locate revision identified by ‘a1c25fe0fc0e‘

Problem Description:

In flash web development, we will use the flash migrate library to migrate the database, so as to submit the changed database model we wrote in the program script to the database without deleting and rebuilding the database model
if we use Python manage.py DB init to create a migration warehouse, and then use the migrate or upgrade in flash migrate, the following two instructions:

python manage.py db migrate
python manage.py db upgrade

Error [flag_migrate] error: can’t locate revision identified by ‘a1c25fe0fc0e’ may appear. The identification number of ‘a1c25fe0fc0e’ corresponds to different database models! As shown in the figure:

resolvent:

The reason for the above error is that flash migrate cannot find the revision of “a1c25fe0fc0e” logo. We just need to indicate the missing logo number in the command
we can use the following commands in order in the shell command line window:

python app.py db revision --rev-id <Fill the prompt's identification number into this location, such as a1c25fe0fc0e above>
python app.py db migrate
python app.py db upgrade

Enter the following command to demonstrate:

then, the database migration succeeds

Finally, if there are deficiencies in the article, criticism and correction are welcome!

Python Error: Process finished with exit code -1073740791 (0xC0000409)

Case 1 is also the case of more on-line): (graphics card) insufficient memory

At this time, we can adjust the memory in pycharm:
Press Shift + Ctrl + A to search for

where:
XMS in xms128m refers to the memory required for program startup, 128M is the size
xmx1011m in Xmx, Xmx refers to the memory required for program running, 1011m is the size
increase it. Of course, your hardware should be able to withstand this setting

Pyexcel Error: xlrd.biffh.XLRDError: Excel xlsx file; not supported

Phenomenon:

code

# content is a table data of byte type
sheet = pyexcel.get_sheet(file_type='xlsx', file_content=content)

report errors

xlrd.biffh.XLRDError: Excel xlsx file; not supported

reason

The installed pyexcel package version is too old

pyexcel-xls==0.5.8
pyexcel==0.5.9.1
pyexcel-xlsx==0.5.6

Solution:

Updated version (latest version)

pyexcel==0.6.7
pyexcel-io==0.6.4
pyexcel-xls==0.6.2
pyexcel-xlsx==0.6.0

How to Solve Pychart configuration import torch error

Pycharm configuration import torch report error Traceback
Error content error screenshot solution
Problem solved

Error content

Traceback (most recent call last):
File “”, line 1, in
File “D:\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py”, line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named ‘torch’
Screenshot of error report
Image:
Solution:
File–>Settings

Python Interpreter

Click the ‘+’
Search torch
Choose install Package

Importing the torch again in the Python Console shows True

Done!

Set the maximum number of Postgres connections Error [How to Solve]

The Postgres version of this tutorial case is 12

Problem Description:

psycopg2.OperationalError: FATAL: sorry, too many clients already on

In the morning, I found that the python back-end service I maintained reported an error. Baidu found that the default maximum concurrency of Postgres was only 100, which led to this problem

Modify tutorial:

cd /var/lib/postgresql/12/main
vi postgresql.auto.conf

Add the following line of code to the file to set the maximum number of connections to 800, the default is 100
max_connections = 800

Restart the service
service postgresql restart

The following is the SQL command to check whether the modification is successful:

# Show the maximum number of connections to the current database
show max_connections;

# Show the number of users currently connected to the data
SELECT COUNT(*) from pg_stat_activity;

# Show details of the current connection, very slow, don't use it
SELECT * FROM pg_stat_activity;

The effect is similar, which indicates that the setting is successful

[Mac Pro M1] Python3.9 import cv2 Error: Reason: image not found

If you forget to copy the original error message, the content is similar to:

>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
"/Users/xxx/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages/cv2/__init__.py", line 4, in <module>
    from .cv2 import *
ImportError: dlopen(/Users/xxx/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages/cv2/cv2.cpython-35m-darwin.so, 2): Library not loaded: /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage
  Referenced from: /Users/xxx/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages/cv2/.dylibs/libavcodec.57.107.100.dylib
  Reason: image not found
>>> `

The breakthrough is also in the error report, which indicates that the libavcodec library may be missing or have problems. The solution is to install the library

Specific:

$ brew install libav
$ brew install ffmpeg

AttributeError: can‘t set attribute [How to Solve]

Traceback (most recent call last):
  File "D:/master/Multi-level-DCNet-master/3leveldcnet.py", line 342, in <module>
    routings=args.routings)
  File "D:/master/Multi-level-DCNet-master/3leveldcnet.py", line 60, in MultiLevelDCNet
    conv, nb_filter = densenet.DenseBlock(x, growth_rate=32, nb_layers=8, nb_filter=32)
  File "D:\master\Multi-level-DCNet-master\densenet.py", line 64, in DenseBlock
    cb = __conv_block(x, growth_rate, bottleneck, dropout_rate, weight_decay)
  File "D:\master\Multi-level-DCNet-master\densenet.py", line 27, in __conv_block
    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(ip)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 575, in __call__
    self.build(input_shapes[0])
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\layers\normalization.py", line 103, in build
    constraint=self.gamma_constraint)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 399, in add_weight
    constraint=constraint)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\backend\tensorflow_backend.py", line 323, in variable
    v.constraint = constraint
AttributeError: can't set attribute

Modify parts of the code:

v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)
    if isinstance(value, np.ndarray):
        v._keras_shape = value.shape
    elif hasattr(value, 'get_shape'):
        v._keras_shape = int_shape(value)
    v._uses_learning_phase = False
    # TODO: move to `tf.get_variable` when supported in public release.
    v.constraint = constraint  #Modify to v._constraint = constraint
    return v