Tag Archives: python

[Solved] uiautomatorviewer Error: Error obtaining UI hierarchy

1. Problem reappearance: when learning appium framework and using uiautomatorviewer to locate Android App controls, directly selecting [device screenshot] will report an error:

2. Solution:

Create a new bat file with the following contents:

adb shell uiautomator dump /sdcard/screen.uix
adb pull /sdcard/screen.uix D:/uiscreen/screen.uix
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png D:/uiscreen/screen.png

In fact, these commands can also be directly input in CMD, but they need to be input every time, which is more troublesome. All commands can be written into bat files and run directly to obtain interface information.

3. Select the path of the picture and uix file in uiautomatorviewer:

My frame is too small. I can’t click the path of the second uix at all. The solution is to press the tab key, locate the button to select the file, and then enter can select it normally.

4. Then you can load the interface and locate the elements normally.

[Solved] cx_Oracle.DatabaseError: Error while trying to retrieve text for error ORA-01804

Error: 

cx_Oracle connect oracle error:

cx_Oracle.DatabaseError: Error while trying to retrieve text for error ORA-01804
sample code:
import cx_Oracle
conn = cx_Oracle.connect(user,pwd, self.ois_tns)

 

Solution: Check the environment variable settings for oracle in the .bash_profile under the Linux user on the server executing the code, as follows.

export ORACLE_HOME=/test/home/oracle/product/11.2.0.4
export LD_LIBRARY_PATH=O R A C L E H O M E / l i b e x p o r t T N S A D M I N = ORACLE_HOME/lib export TNS_ADMIN=ORACLEHOME/libexportTNSADMIN=ORACLE_HOME/network/admin

 

Django CSV file Error: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start

This csv file I opened in jupyter using pd.read_csv open no problem

But after I cleaned the data and saved it as a new csv, I couldn’t open it and got an error

Solution: in the views.py direct cleaning work, the data will be stored in order into a list, using a loop to iterate through the database, the following is the code (less efficient after all is iterative. Welcome to share a better way)

df = pd.read_csv(r"xxxxx\xxx.csv", encoding='utf-8')
... # datas clean up
ls = []
for index, row in df.iterrows():
     res = []
     for i in df:
         res.append(row[i])
            ls.append(res)
for i in range(len(ls)):
    try:
        XXX.objects.create(title=ls[i][0], rating=ls[i][1])
    except Exception as e:
        print(e)
return HttpResponse('Datas save successfully')

[Solved] transformers Install Error: error can‘t find rust compiler

Install transformers after reinstalling the system. If you encounter a bug, record it and check it later.

When reinstalling with pip install transformers command under windows, an error is reported:

error: can't find Rust compiler
      
    If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
      
    To update pip, run:
      
        pip install --upgrade pip
      
    and then retry package installation.
      
    If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
    [end of output]
  
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

According to the error prompt, first run pip install -- upgrade pip is invalid, and then install Rust Compiler according to the error prompt. First go to the official website to download the corresponding installation package, select the 64-bit installation file according to my actual situation, then click the downloaded exe file to install, and select the default configuration during the installation process.

According to the instructions on the official website, all tools of rust are in the  ~/.cargo/bin directory includes commands:  rustc, cargo and rustup . Therefore, it needs to be configured into the environment variable, but windows will configure it automatically, but the configured environment variable will take effect only after restarting the computer under windows. After restarting, run the installation command again:

pip install transformers

The result is a successful installation. The screenshot is as follows:

[Solved] MXNet Error: ImportError: cannot import name _LIB

Reason: it should be that there are too many installation files, too many versions and chaotic installation of PIP and python in the system, so those unnecessary files need to be deleted

Solution: clean up the PIP installation location (operation in docker environment)

apt-get install python-pip
find/-name pip

Delete all folders output by the command, then uninstall PIP and reinstall it

apt-get remove python-pip

apt-get install python-pip

Check it again

find/-name pip

The correct should be as follows

The first folder should not matter. The following two folders must not be too many. Then install mxnet, and there will be no error when importing

[Solved] Ubuntu pip Install Error: which is not on PATH

First, let’s take a look at the warning information

  WARNING: The script normalizer is installed in '/home/llxy/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Solution: Configure environment variables

gedit ~/.bashrc
# Add the path at the end of the file, which comes from the warning issued when installing pip in the first step
export PATH=/home/llxy/.local/bin:$PATH
source ~/.bashrc

[Solved] error: the following arguments are required (Default parameters are set)

When using the arguparse parameter list, if a parameter specifies a default value, it still displays: error: the following arguments are required

Solution:

1. Replace required=True with required=False.

2. Add — before parameter name.

As follows:

parser.add_argument('--mode', '-M', dest='mode', action='store', required=True,
                    choices=['train', 'test'], default='train',
                    help='Mode in which the script is executed.')

DLL load failed while importing rdBase [How to Solve]

At first, there was no problem with using rdkit. When deep Chem is installed later, this error will be reported,

DLL load failed while importing rdBase

The rdkit package may be damaged, so you can reinstall the rdkit. The installation code is as follows

conda install -c rdkit rdkit

However, it is recommended to install deepchem in a separate virtual environment, it will affect many of the previously installed packages, such as numpy and so on

[Solved] OpenCV Import Error: ImportError: numpy.core.multiarray failed to import

cv2 import Error:

(paddle) C:\Windows\system32>python
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cv2
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “D:\anaconda3\envs\paddle\lib\site-packages\cv2\__init__.py”, line 8, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
>>> exit()

Solution:

pip install -U numpy 

New problems,

(paddle) C:\Windows\system32>pip install -U numpy
Requirement already satisfied: numpy in d:\anaconda3\envs\paddle\lib\site-packages (1.19.3)
Collecting numpy
  Downloading numpy-1.22.3-cp38-cp38-win_amd64.whl (14.7 MB)
     |████████████████████████████████| 14.7 MB 547 kB/s
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 1.19.3
    Uninstalling numpy-1.19.3:
      Successfully uninstalled numpy-1.19.3
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
paddlepaddle-gpu 2.2.2 requires numpy<=1.19.3,>=1.13; python_version >= "3.5" and platform_system == "Windows", but you have numpy 1.22.3 which is incompatible.
openvino 2021.4.2 requires numpy<1.20,>=1.16.6, but you have numpy 1.22.3 which is incompatible.
openvino-dev 2021.4.2 requires numpy<1.20,>=1.16.6, but you have numpy 1.22.3 which is incompatible.
Successfully installed numpy-1.22.3

However, I tested it and found that this new error has not caused too many problems.

To meet compatibility, if you want to change back to the version, you can

pip install numpy==1.19.3
pip uninstall opencv-contrib-python
conda install opencv

Note that the following instructions will install (uninstall) the latest version of OpenCV,

pip (un)install opencv-contrib-python

 

Reference:

https://stackoverflow.com/questions/20518632/importerror-numpy-core-multiarray-failed-to-import