Category Archives: Python

[Solved] Python3 Error: ModuleNotFoundError: No module named ‘_bz2’

Python 3 reported an error: modulenotfounderror: no module named ‘_ bz2’

system information

System: Ubuntu 1804 lts

Python version: Python 3.7

Error message

from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

Solution:

1. installation
sudo apt install bzip2-devel

2. Find the file _bz2.cpython-37m-x86_64-linux-gnu.so


3. Modify the file name
If your python version is 3.6, it is 36m, mine is python3.7, you have to change the file name to 37m, and copy it to the python3 installation directory
mv _bz2.cpython-36m-x86_64-linux-gnu.so _bz2.cpython-37m-x86_64-linux-gnu.so
cp _bz2.cpython-37m-x86_64-linux-gnu.so /usr/local/python3/lib/python3.7/lib-dynload/

[Solved] Pycharm Error: Error running ‘XXX‘: Cannot run program “XXX\python.exe“ (in directory “XXX“)

Pycharm Error: Error running ‘XXX‘: Cannot run program “XXX\python.exe“ (in directory “XXX“)

 

Solution:

1. Look at the path when the error is reported. If it does not correspond to the environment, it indicates that there is a problem
2. Exit pycharm – find the project file, delete the. Idea hidden file – reopen the project

[Solved] Python Error: CentOS failed to send mail without any error message

CentOS failed to send mail without any error message

A mail sending program written in Python runs successfully on the local computer windows10 and python 3.10.0, but fails to run on Alibaba cloud server CentOS 7.6 and python 3.6.8, and there is no error message (it may also timeout, but I am not patient to wait for the error result).

Solution:

Previous code:

1 #163 email
2 mail_host = 'smtp.163.com'
3 smtpObj = smtplib.SMTP()
4 smtpObj.connect(mail_host,25)
5 
6 # or
7 mail_host = 'smtp.163.com'
8 smtpObj = smtplib.SMTP(mail_host, 25)

After modification:

#163 email
mail_host = 'smtp.163.com'
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host,25)

or:

mail_host = 'smtp.163.com'
smtpObj = smtplib.SMTP_SSL(mail_host, 463)

Attachment: centos7 uses Python STMP to send mail without sending or error prompt

Python 3: How to Solve Demjson Install Error

The following error occurs when Python 3 installs demjson 2.2.4

error in demjson setup command: use_2to3 is invalid

Since demjson 2.2.4 is compatible with python2 and python3, some code needs to be converted when the installation environment is python3

Setuptools no longer supports 2to3 builds from version 58.0.0, so demjson 2.2.4 is no longer available after installation,

It can be solved by demoting the version of setuptools

pip install --upgrade setuptools==57.5.0

Ubuntu1.8 Install python3.7pip Error: “subprocess.CalledProcessError…lsb_release”

background

Install Python 3.7 on a Ubuntu 18.04. After that, try the PIP list command, and a long list of errors appear. I’ll post the last few lines:

File “/usr/local/lib/python3.7/subprocess.py”, line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ‘(‘lsb_release’, ‘-a’)’ returned non-zero exit status 1.

When executing the PIP list command, the LSB cannot be found_Release – a this command
solutions

1. LSB found_Release.py this file

sudo find/-name ‘lsb_release.py’

The results shown here are as follows. There may be differences between different system versions:

/usr/share/pyshared/lsb_release.py
/usr/lib/python2.7/dist-packages/lsb_release.py
/usr/lib/python3/dist-packages/lsb_release.py

2. Select the path containing python3 and copy the file to the error path/usr/local/lib/python3.7/

sudo cp /usr/lib/python3/dist-packages/lsb_release.py/usr/local/lib/python3.7/

Try to execute PIP list again and return to normal.

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')

[Solved] Uncaught TypeError: Cannot read property ‘ownerDocument’ of null

/*********************************************************************

 * Uncaught TypeError: Cannot read property 'ownerDocument' of null
 * Description.
 * Trying to load the SVG file content via JS Ajax and then dynamically insert it into the div, reporting this error.
 * Solution, directly change the svg suffix to html, it works.
 *
 ********************************************************************/

For this reported error, did not understand much, anyway, after changing the file suffix (.svg -> .html), it works.