Tag Archives: python

Solution of selenium driven edge error reporting

Solution of selenium driven edge error reporting

Selenium uses edge to run an error message: ‘microsoftwebdriver. Exe’ executable needs to be in path

// An highlighted block
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH

Problem cause: the driver file name written in selenium is inconsistent with the actual driver file name

Solution: rename the downloaded driver file msedgedriver.exe to Microsoft webdriver.exe, save it and run it again

Error when starting Python in Windows

Error message

Start Python 3.6 in the windows command line environment and report the following error

C:\Users\gaozh>python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "C:\Anaconda3\lib\site.py", line 418, in register_readline
    readline.read_history_file(history)
  File "C:\Anaconda3\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "C:\Anaconda3\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
    for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 407: illegal multibyte sequence

terms of settlement

The way to solve this problem is to modify the corresponding code in line 82 of the file C: \ anaconda3 \ lib \ site packages \ pyreadline \ lineeditor \ history. Py , add the coding format as UTF-8 , and then restart python.

Reference articles

https://github.com/pyreadline/pyreadline/issues/38

Error reporting using selenium in pycharm

The error information is as follows:

  That is, for the chrome driver to execute, it must be added to the environment variable

Download the chrome driver that is consistent with the version of Google browser on your computer, and unzip the chrome driver into the scripts folder of Python

Error in installing paddlenlp on pip on Windows

1. PIP installation paddlenlp reports an error

An error is reported when PIP installs paddlenlp on windows, as follows:

 distutils.errors.DistutilsError: Command '['C:\\Users\\yuanyangping\\.conda\\envs\\yyp_paddle\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\YUANYA~1\\AppData\\Local\\Temp\\tmphix_2c5i', '--quiet', 'setuptools_scm']' returned non-zero exit status 1.

Some methods to solve the problem are queried, but they are not effective, so they are not listed one by one.

2. Solutions

Pay attention to one detail. It is normal to download paddlenlp, but an error is reported only after downloading seqeval, as follows:

Collecting paddlenlp
  Downloading http://mirrors.aliyun.com/pypi/packages/b0/7d/6c24cda54d018d350ee342f715523ade7871660444ed95f3d3e753d6f388/paddlenlp-2.0.8-py3-none-any.whl (571 kB)
     |████████████████████████████████| 571 kB 467 kB/s
Collecting seqeval
  Downloading http://mirrors.aliyun.com/pypi/packages/9d/2d/233c79d5b4e5ab1dbf111242299153f3caddddbb691219f363ad55ce783d/seqeval-1.2.2.tar.gz (43 kB)
     |████████████████████████████████| 43 kB 656 kB/s
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\yuanyangping\.conda\envs\yyp_paddle\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\YUANYA~1\\AppData\\Local\\Temp\\pip-install-n4_d0gwa\\seqeval_6f8ecdc805df4aa092ecc3df7994196f\\setup.py'"'"'; __file__='"'"'C:\\Users\\YUANYA~1\\AppData\\Local\\Temp\\pip-install-n4_d0gwa\\seqeval_6f8ecdc805df4aa092ecc3df7994196f\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\YUANYA~1\AppData\Local\Temp\pip-pip-egg-info-zp58k0dh'

Therefore, can you install seqeval first and then paddlenlp, and execute two commands in succession, as follows:

pip install seqeval
pip install paddlenlp

Then paddlenlp is successfully installed
If an error is still reported, specify the version of seqeval as 0.0.3

3. Extension

The above reason should be that there is a problem with the configuration information when downloading and installing seqeval
therefore, if similar error reports occur when installing other software, you can install the software where the error is reported first, and then install the main software you want to install.

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

Pandas read_csv pandas.errors.ParserError: Error tokenizing data

What you will learn?
pandas read_csv escape commas and double qoutes
Prepare datas

# test.csv or test.txt
"1","123","4","\"data\""
"test","123","4","if(\"data\" = \"<test>\", (10*24))"

Wrong-way

import pandas as pd

datas = pd.read_csv('test.txt', header=None, skip_blank_lines=True)

You got

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader.read()

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._read_low_memory()

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._read_rows()

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows()

pandas\_libs\parsers.pyx in pandas._libs.parsers.raise_parser_error()

ParserError: Error tokenizing data. C error: Expected 4 fields in line 2, saw 5

Right way

import pandas as pd

datas = pd.read_csv('test.txt', header=None, skip_blank_lines=True, escapechar='\\')

Digression

Many people on the Internet encounter this problem and add a parameter: error_bad_Lines = false (tested, the second row will be lost for the above data). If the amount of data is not large, check the method of the specified row: cat – N filename | head – N end_line_no| tail -n +start_line_no

[Solved] HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/saved_model

Cause:

Originally, there was a saved_model folder under the two folders sort_change_nlp and sort_nlp, but the names were different, one was saved_model and the other was saved_model_copy. Using saved_model in http_sever clock, the following error occurred:

model = YesOrNoModel.from_pretrained(model_name)

def is_model_answer(query):
    for rule in base_data.q_v_model_list:
        result1 = re.compile(rule).findall(query)
        if len(result1):
            return "saved_model"
    return ""
  model_name = is_model_answer(query)
    print(f"model_name={model_name},answer={answer}")
    if len(model_name):
        model = YesOrNoModel.from_pretrained(model_name)

Error:

ssh://[email protected]:22/usr/bin/python -u /opt/program_files/python/local_map_python_work/judge/sort_proj/test.py
404 Client Error: Not Found for url: https://huggingface.co/saved_model/resolve/main/config.json
Traceback (most recent call last):
  File "/root/.local/lib/python3.6/site-packages/transformers/configuration_utils.py", line 520, in get_config_dict
    user_agent=user_agent,
  File "/root/.local/lib/python3.6/site-packages/transformers/file_utils.py", line 1371, in cached_path
    local_files_only=local_files_only,
  File "/root/.local/lib/python3.6/site-packages/transformers/file_utils.py", line 1534, in get_from_cache
    r.raise_for_status()
  File "/usr/local/python3/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/saved_model/resolve/main/config.json
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/program_files/python/local_map_python_work/judge/sort_proj/test.py", line 22, in <module>
    model = YesOrNoModel.from_pretrained("saved_model")
  File "/root/.local/lib/python3.6/site-packages/transformers/modeling_utils.py", line 1196, in from_pretrained
    **kwargs,
  File "/root/.local/lib/python3.6/site-packages/transformers/configuration_utils.py", line 455, in from_pretrained
    config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/root/.local/lib/python3.6/site-packages/transformers/configuration_utils.py", line 532, in get_config_dict
    raise EnvironmentError(msg)
OSError: Can't load config for 'saved_model'. Make sure that:
- 'saved_model' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'saved_model' is the correct path to a directory containing a config.json file

 

Solution:
The reason is that http.server is a level folder with sort_change_nlp and sort_nlp, so the path passed in when calling the model should be: sort_change_nlp/saved_model or sort_nlp, saved_model_copy

Python Error: mongod: error while loading shared libraries: libcrypto.so.1.1

Reading guide

After installing mongodb in Python, the following error is reported when executing mongod

mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

Solution:

Find the virtual environment used. For example, the name of my virtual environment is torch , and use the following command to check whether the libcrypto. So. 1.1 file exists in the environment

#Switch to the lib directory
cd /root/anaconda3/envs/torch/lib
# Check if the file exists
ls -lh | grep "libcrypto.so.1.1"
-rwxrwxrwx 1 root root 3.2M Jun 4 15:43 libcrypto.so.1.1
# If the file exists execute the following command
sudo ldconfig /root/anaconda3/envs/torch/lib

If there is no in the Lib directory, use the following command for global search

find/-name 'libcrypto.so.1.1'

Observe the search results and find the existing directory by using the above sudo ldconfig directory path

[Solved] C error: expected 1 fields in line 3, saw 2 processing method

1. There is a CSV file that I read directly with the pandas library, and an error is reported: error tokenizing data. C error: expected 1 fields in line 3, saw 2. There should be a problem with the format. It can only be opened after it is opened and saved again. However, because there are many files, I wonder if I can read the CSV file by other methods;

2. Read through the CSV library, traverse, and merge:

import pandas as pd
import csv


path = 'the location of file'

test = pd.DataFrame()
data = csv.reader(open(path, 'r'))
for d in data:
    # print(d)
    result = pd.DataFrame(d).T
    test = pd.concat([test,result])
test = test.reset_index(drop = True)

3. Finally, you will get the dataframe of test, which is the same as the file read by pandas after saving

Flash cli encountered a keyerror “migrate” [How to Solve]

Flash management command-line tool. I use flash cli

Then, using any command related to flash DB will cause the problem of keyerror “migrate”

No solution was found on the Internet

Therefore, I started to think step by step and finally determined that the biggest problem without the migrate command was that when I executed the flash DB XX command, I didn’t find the corresponding app. The command line didn’t know which app I wanted to run, so I didn’t find the app associated with DB, that is, I didn’t find it

Migrate = migrate (APP = app, DB = dB), so an error is reported

Therefore, to use the flash command, you first need to declare flash_ APP

That is, enter in terminal

export FLASK_APP=The name of the app you want to run

=Do not leave a space before or after, otherwise bad assignment will be reported

Then enter flash DB migrate again and it will be normal

[Solved] Python matplotlib Error: RuntimeError: In set_size: Could not set the fontsize…

Problem
Error when saving image:RuntimeError: In set_size: Could not set the fontsize

Traceback (most recent call last):
  File "/Users/robin/MLcode/Pycharm_Project/tensorflow/2021/0823_face_recognition_environment/0827_img_quality_analysis_v4.py", line 1556, in <module>
    image_cluster_analysis()
  File "/Users/robin/MLcode/Pycharm_Project/tensorflow/2021/0823_face_recognition_environment/0827_img_quality_analysis_v4.py", line 1549, in image_cluster_analysis
    image_showing(img_compressed)
  File "/Users/robin/MLcode/Pycharm_Project/tensorflow/2021/0823_face_recognition_environment/0827_img_quality_analysis_v4.py", line 1408, in image_showing
    plt.savefig(img_name)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/pyplot.py", line 722, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/figure.py", line 2180, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2082, in print_figure
    **kwargs)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 579, in print_jpg
    buf, size = self.print_to_buffer()
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 535, in print_to_buffer
    FigureCanvasAgg.draw(self)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
    self._update_title_position(renderer)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2556, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 210, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 250, in _get_agg_font
    font.set_size(size, self.dpi)
RuntimeError: In set_size: Could not set the fontsize

Solution:

The source of the problem is figure_Size and DPI :

The following two codes are different:

figure_size = (6.40, 4.80)
plt.figure(figsize=figure_size, dpi=100)

And:

figure_size = (640, 480)
plt.figure(figsize=figure_size, dpi=1)

Note:

figsize : width, height in inches, default: (6.4, 4.8) , that is, the picture size in inches. The default value in Matplotlib is (6.4, 40.8) DPI : dots (or pixels) per inch, default: 100.0 , that is, the number of pixels per inch. The default value is 100

Although the above two representations seem to be the same, an error is reported by using DPI = 1. (I won’t delve into it for the time being)