Tag Archives: Python

[Solved] Python error: attributeerror: type object ‘STR’ has no attribute ‘_name_’ (machine learning practice treeplotter code)

Error message:

When learning the book machine learning practice, I ran according to the code in the book and made an error, but there was no error prompt in the code. The error codes are as follows:

if type(secondDict[key])._name_ == 'dict':

Errors are reported as follows:

AttributeError: type object 'str' has no attribute '_name_'

Attribute error: the type object “STR” has no attribute “name”,

The error is caused by different versions. The author uses version 2. X, while I use version 3.7. X.

Solution

The type object “STR” in Python 3 does not have the “_name_” attribute, so we need to remove the attribute. In addition, this judgment statement was originally used to judge whether the node type is dict (Dictionary), but because the single quotation mark (”) is added, it becomes a string, which will cause other errors, so we also need to remove the single quotation mark.

Modify the error code as follows:

if type(secondDict[key]) == dict:

Just run it now.

[Solved] ModuleNotFoundError: No module named’usysconfigdata u x86 64-u-gnu’

Technical background

In the last blog post, I performed the update of CONDA and installed gxx with CONDA_After linux-64, when some PIP instructions are executed, the following error messages will be given:

$ python3 -m pip list
Traceback (most recent call last):
  File "/home/dechin/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/dechin/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/__main__.py", line 29, in <module>
    from pip._internal.cli.main import main as _main
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/configuration.py", line 27, in <module>
    from pip._internal.utils.misc import ensure_dir, enum
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 42, in <module>
    from pip._internal.locations import get_major_minor_version, site_packages, user_site
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/__init__.py", line 9, in <module>
    from . import _distutils, _sysconfig
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/_distutils.py", line 18, in <module>
    from .base import get_major_minor_version
  File "/home/dechin/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/base.py", line 14, in <module>
    site_packages = sysconfig.get_path("purelib")  # type: typing.Optional[str]
  File "/home/dechin/anaconda3/lib/python3.8/sysconfig.py", line 521, in get_path
    return get_paths(scheme, vars, expand)[name]
  File "/home/dechin/anaconda3/lib/python3.8/sysconfig.py", line 511, in get_paths
    return _expand_vars(scheme, vars)
  File "/home/dechin/anaconda3/lib/python3.8/sysconfig.py", line 172, in _expand_vars
    _extend_dict(vars, get_config_vars())
  File "/home/dechin/anaconda3/lib/python3.8/sysconfig.py", line 559, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/home/dechin/anaconda3/lib/python3.8/sysconfig.py", line 430, in _init_posix
    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_x86_64_conda_linux_gnu'

Problem location and solution

After a round of searching, the cause of the problem is finally located as: a backup file is lost in a certain version of Python. Usually, there are two identical in the same version of Python_ sysconfigdata_ x86_ 64_ conda_ cos6_ linux_ GNU. Py files and _ sysconfigdata_ x86_ 64_ conda_ linux_ GNU. Py file. Some programs depend on one of them during operation, so what we need to do is to retrieve whether these two files exist in the system:

$ sudo find ~ -name _sysconfigdata_x86_64*
[sudo] dechin password is:
/home/dechin/anaconda3/lib/python3.8/_sysconfigdata_x86_64_apple_darwin13_4_0.py
/home/dechin/anaconda3/lib/python3.8/__pycache__/_sysconfigdata_x86_64_apple_darwin13_4_0.cpython-38.pyc
/home/dechin/anaconda3/lib/python3.8/_sysconfigdata_x86_64_conda_cos6_linux_gnu.py

Here we find that there is only one under the Python 3.8 Path currently used_sysconfigdata_x86_64_conda_cos6_linux_GNU.Py file without _sysconfigdata_x86_64_conda_linux_Gnu.py file, so we only need to make a copy of the file:

$ cp /home/dechin/anaconda3/lib/python3.8/_sysconfigdata_x86_64_conda_cos6_linux_gnu.py /home/dechin/anaconda3/lib/python3.8/_sysconfigdata_x86_64_conda_linux_gnu.py

At this time, execute the PIP instruction again:

$ python3 -m pip listPackage                            Version
---------------------------------- -----------------
absl-py                            0.13.0
adamod                             0.0.3
affinity                           0.1.0
alabaster                          0.7.12
anaconda-client                    1.8.0
anaconda-navigator                 1.10.0
anaconda-project                   0.10.1
anyio                              2.2.0
...

Successful operation, problem solved.

Summary summary

In the recent version update of CONDA, the files under the path may be deleted_sysconfigdata_x86_64_conda_linux_GNU module related backup file, which may be relied on during the operation of some other software, which will lead to the problem that the error module cannot be found during the operation. Finally, we solved the problem by copying and backing up the file again.

 

[Python] MAC uses the picture recognition pytesseract method to report an error

1、 Premise:

Pyteseract image recognition is used in Python, and an error is reported:

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it’s not in your path

2、 Solution

Cause of problem:

Installed pytesseract using pip, but forgot to install the Tesseract binary.

First, go to the pytesseract.py file and find it

tesseract_cmd

Change the path

 

 

Amend to read:

 

 

 

[transfer]

1. Installation command on Linux

sudo apt update
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev

2. MAC installation command

brew install tesseract

3. Installation command on Windows

from https://github.com/UB-Mannheim/tesseract/wiki Download binaries. Then add pytesseract.pytesseract.tesseract_ CMD = 'C: \ \ program files (x86) \ \ Tesseract OCR \ \ Tesseract. Exe' into the script. (if necessary, replace the path of the Tesseract binary file)

 

 

Article reference:

Thanks for Levi’s article: how to use pytesseractnotfounderror (Tesseract OCR) in Python

Python compiles and installs under Linux and reports an error: makefile: 1141: install

Execute under normal conditions:
./configure
make & amp& amp; Make install
you can install Python directly, but you report an error after updating the black layout
after checking, it is found that python3.8 is installed in Ukrainian territory, and uninstalling the components that will affect Ukrainian territory,
so you have to keep python3.8 and install your own python3.7.8
1. Install GCC and G + +
sudo apt get GCC
sudo apt get G + +

2. Recompile and install Python
     (PS: after GCC and G + + are installed, errors are still reported during compilation and installation. The solution can be omitted if GCC and G + + are updated and compiled normally:)
       sudo apt-get install build-essential
       sudo apt-get update
       sudo apt-get upgrade
       sudo apt-get dist-upgrade
       sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
       sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
       sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
       sudo apt-get install libssl-dev openssl
       sudo apt-get install libffi-dev

Compile and install Python:
./configure
make & amp& amp; Make install
check whether Python installation is successful:     
Python 3.7 – V
pip3.7 – V

4. Enter pychart and find that there are no environment variables for Python 3.7, only Python 3 and python 3.8
Click:
Settings – & gt; Project:pythonproject-> Python Intepreter-> Click the settings Icon (in the upper right corner)
– & gt; add-> Select existing environment – & gt; Fill in the path:/usr/local/bin/Python 3.7 – & gt; Check make available to all projects

5. Check that Python 3.7 is displayed in the lower right corner of pychart

Python uses poetry to install Sqlalchemy with an error attributeerror solution

This article mainly introduces the solution of “attributeerror ’emptyconstraint’ object has no attribute ‘allowed’ when executing PIP install Sqlalchemy in Python, but the error is reported when executing poetry installation.

Original address: Python uses poetry to install Sqlalchemy error attributeerror solution

pip install poetry Export requirements.txt Error: ERROR: In –require-hashes mode, all requirements must have their versions pinned with ==. These do not: cffi>=1.1 from https://…..

background

Python 3.9

pip 21.2.3

poetry   1.1.8

Execute the command to export requirements.txt

 poetry export  -f requirements.txt --output requirements.txt

seerequirements.txt

Each library has a hash encryption field

Execute the PIP install command

pip3 install --no-cache-dir --upgrade  -r requirements.txt

It’s wrong

#8 28.40 Collecting websockets==10.0
#8 28.51   Downloading websockets-10.0-cp39-cp39-manylinux2010_x86_64.whl (107 kB)
#8 29.38 Collecting cffi>=1.1
#8 29.38 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
#8 29.38     cffi>=1.1 from https://files.pythonhosted.org/packages/be/2a/6d266eea47dbb2d872bbd1b8954a2d167668481ff34ebb70ffdd1113eeab/cffi-1.14.6-cp39-cp39-manylinux1_x86_64.whl#sha256=f3ebe6e73c319340830a9b2825d32eb6d8475c1dac020b4f0aa774ee3b898d1c (from bcrypt==3.2.0->-r /code/requirements.txt (line 19))
------
executor failed running [/bin/sh -c pip install --no-cache-dir --upgrade -r /code/requirements.txt]: exit code: 1

Troubleshooting ideas

Uninstall cffi library and reinstall it. No

Regenerate the requirements.txt file and then install it. No

No, Google searched and found the issue of similar problems. It seems that it is a known problem, and the official poetry hasn’t fixed it yet. It only provides a way to avoid it

https://github.com/actions/virtual-environments/issues/2245

Solution

This flag is passed in the poetry export command  — without-hashes

poetry export --without-hashes -f requirements.txt --output requirements.txt

I use this method. It can be used in practice. It is suitable for small partners who use poetry

The following scenes have not been tried

Scene 1

Stop using PIP — constraints flag to pass packages with fixed hashes

Scene 2

If you use PIP directly, fix it to versions before 20.3

python -m pip install --upgrade pip==20.2.4

Scene 3

If you are using another   Virtualenv depends on pip. Please ensure that its version is fixed

python -m pip install --upgrade virtualenv==20.0.26

Or use the environment variable virtualenv_ PIP=20.2.4

Python Files Error: SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: tr

Syntaxerror was just reported when running the python file: ‘Unicode error)’ Unicode scape ‘codec can’t decode bytes in position 2-3: tr. in fact, the reason for this error is the escape problem.

sys.path.append('c:\Users\mshacxiang\VScode_project\web_ddt')

Cause analysis: in the windows system, the file path can be read by \, but in the Python string \, there is an escape meaning,

For example, \ t can represent tab and \ n represents line feed, so we need to take some measures to make \ not be interpreted as escape characters. There are currently 3 solutions

1. Add r before the path to keep the original value of the character.

sys.path.append(r'c:\Users\mshacxiang\VScode_project\web_ddt')

2. Replace with double backslash

sys.path.append('c:\\Users\\mshacxiang\\VScode_project\\web_ddt')

3. Replace with forward slash

sys.path.append('c:/Users/mshacxiang/VScode_project/web_ddt')

Python automatic error [How to Solve]

Use Python today. However, I met a mistake. A crazy stroke. Some say the path is wrong, others say it is… The information found on the Internet is also very few. Later, I suddenly found that the elements I can see temporarily on the page can be located and operated. What cannot be seen cannot be carried out… PS I didn’t join the full screen at this time

Seeing this, I suddenly thought whether it was caused by the nonfull screen of the page. OK. He really caused it. With the full-screen code, there will be no problem

driver.maximize_window()