Tag Archives: Python

[Solved] jenkins Build python Program Error: ModuleNotFoundError: No module named ‘htmltestreport’

Background:

The project is built based on virtual environment, and the third-party packages are actually installed in:

E:\PyProject\py_basic\Lib\site-packages is not the same directory as Python installation directory

Question:

Both pycham and CMD can operate normally, but Jenkins build error:

C:\Users\86158\.jenkins\workspace\ihrm_code>python run_suite.py 
Traceback (most recent call last):
  File "run_suite.py", line 3, in <module>
    from htmltestreport import HTMLTestReport
ModuleNotFoundError: No module named 'htmltestreport'

Solution:

Add environment variables to Jenkins. This problem is usually caused by the configuration of environment variables

[Solved] Python Error: ModuleNotFoundError : No Module named ‘pip._internal’

1. Error reporting when using PIP:

1 Traceback (most recent call last):
2   File "/usr/local/bin/pip", line 7, in <module>
3     from pip._internal import main
4 ImportError: No module named _internal

2. Solution:

Update pip

python3 -m pip install --upgrade pip
pip install --upgrade pip

3. Completion

After all updates are installed successfully, PIP – V can run normally and use pip.

[Solved] Python Run Selenium Error: NameError: name ‘By’ is not defined

NameError: name 'By' is not defined

Reason: the by class does not have a package, and the system cannot recognize the by object

Solution:

Import by package:

from selenium.webdriver.common.by import By

———————————-Warm tips—————————————

Automatic package guide shortcut: Alt + ENTER

[Solved] python MATLAB Error: OSError: MATLAB Engine for Python supports Python version 2.7, 3.4, 3.5 and3.6, but your version of python is 3.8

Because the coordinates of broken line graph and curve graph are to be read recently, Python is used to call matlab to try, but an error is reported in this process:

The matlab2017b I use does not support Python 3 Version 8.

Solution:

I chose to create a virtual environment in anaconda.

As follows:

Because the maximum version of 3.6 is supported, a version of 3.6 is created

Open pycharm, set it in setting, and select Add

Generally, the virtual environment created is in the envs of anaconda

After setting the environment, it can be executed successfully again

Test:

Run successfully

[Solved] 64-bit Python calls 32-bit Oracle client error: Cx_Oracle.DatabaseError: DPI-1047

problem

The operating system is 64 bit Python and 32 bit Oracle client. For other reasons, the Oracle client cannot be changed to 64 bit, resulting in Cx_Oracle64 bit cannot be used, CX_Oracle32 bit cannot be installed.

reason

Under Windows environment, if 64 bit Python is installed, CX_Oracle is used, the 64 bit Oracle client is called by default. In this case, we can only install Cx_Oracle win_Amd 64-bit version.

Solution:

1. First install CX_Oracle matching the current Python version, my is Python 3.8. The installed version is: Cx_Oracle-8.3.0-cp38-cp38-win_amd64.whl

2. Download the relevant Oracle instantclient (instant client) and unzip it to a folder convenient for calling

Download address: https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html

The version I downloaded is: instantclient-basiclite-windows-x64-19.13.0.0.0dbru.Zip, you can try several times, there is always one for you

3. Unzip the instantclient and change the environment variable in the Python code to adjust the Oracle driver location.

My unzipped address is:

E:\software\Python\instantclient-basiclite-windows.x64-19.13.0.0.0dbru

The code adjustment method is

import os

os.environ[‘path’] =  r’E:\software\Python\instantclient-basiclite-windows.x64-19.13.0.0.0dbru\instantclient_19_13′

import cx_Oracle

Now CX_Oracle can call normally

[Solved] python Connect Oracle Error: DPI-1047

Prompt when Python connects to Oracle:: databaseerror: dpi-1047: cannot locate a 64 bit Oracle Client Library: “the specified module could not be found” See https://oracle.github.io/odpi/doc/installation.html#windows for help

Enter according to the error prompt https://oracle.github.io/odpi/doc/installation.html#windows, download the corresponding instant client package, then unzip the configuration environment variables and run it again. Generally, it can run successfully to solve the problem.

If dpi-104 error is still prompted, you need to check whether VC + + is installed. The check method is to run genezi.com under the downloaded instant client directory Exe program. For example: C:\Oracle\instantclient_21_3\genezi.exe. If there is an error during execution, it means VC_redist is not installed correctly. reenter https://oracle.github.io/odpi/doc/installation.html#windows Page, download the corresponding VC according to the corresponding Oracle version_redist.exe version.

Download and install to solve the problem.

[Solved] python Install pip Error: zipimport.ZipImportError: can’t decompress data; zlib not available

Phenomenon:

Solution:

1. Install dependent packages

yum -y install zlib*

2. Recompile Python

#The catalog is based on the production environment itself
[[email protected] software]# cd Python/
[[email protected] Python]# ./configure --prefix=/usr/local/python3

#Compile and install
[[email protected] Python]# make && make install

# re-install
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py

[Solved] Python: third-party library fire Install Error

1. Linux Environment

report errors

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting fire
  Downloading https://mirrors.aliyun.com/pypi/packages/11/07/a119a1aa04d37bc819940d95ed7e135a7dcca1c098123a3764a6dcace9e7/fire-0.4.0.tar.gz (87 kB)
     |????????????????????????????????| 87 kB 3.8 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6x44h_/fire/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6x44h_/fire/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 /tmp/pip-pip-egg-info-szF2KD
         cwd: /tmp/pip-install-6x44h_/fire/
    Complete output (1 lines):
    error in fire setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Solution:

This problem is mainly because the version of setuptools is too low, so you only need to upgrade the software. Install fire after upgrading the version of setuptools

]# pip install setuptools -U
]# pip install fire

2. Windows Environment

report errors

(env) [email protected] python> pip install fire
Traceback (most recent call last):
  File "D:\Python27\Lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "D:\Python27\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "F:\workspace\cli\python\env\Scripts\pip.exe\__main__.py", line 4, in <module>
  File "f:\workspace\cli\python\env\lib\site-packages\pip\_internal\cli\main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "f:\workspace\cli\python\env\lib\site-packages\pip\_internal\cli\autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "f:\workspace\cli\python\env\lib\site-packages\pip\_internal\cli\main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "f:\workspace\cli\python\env\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 25, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
    _BaseBar = _select_progress_class(IncrementalBar, Bar)  # type: Any
  File "f:\workspace\cli\python\env\lib\site-packages\pip\_internal\cli\progress_bars.py", line 48, in _select_progress_class
    six.text_type().join(characters).encode(encoding)
LookupError: unknown encoding: cp65001

Solution

This problem is mainly caused by the character encoding on the command line. Some characters cannot be used normally. Just modify the default character encoding. If you continue to report errors, you can modify it to other character codes

(env) [email protected] python> chcp 1252 //Modify to 1252 (ANSI)
(env) [email protected] python> pip install fire

 

[Solved] Python request Error: requests.exceptions.ReadTimeout: HTTPSConnectionPool (xxxx)

Screenshot of the problem:

Mental process

First, the request parameters are determined. The URLs are consistent, but an error is reported

Method 1:

import requests

requests. get(‘ https://www.google.com/ ‘,verify=False)

If it’s not solved, it’s not the agent’s reason

Method 2:

session = requests. session()

session. keep_ Alive = false # close redundant connections

Using session error reporting session request

It still hasn’t been solved. Generally, it can be solved at this step, but an error is still reported when executing python

Finally, I found that I was out of my mind. Since the header request header directly copies other items, just annotate the “content length”: “143” in it. Only remember that the header in the later step is better to use the header of the current interface. You can delete redundant values yourself. It’s not convenient to pull an item from other items, which will increase the troubleshooting time