Ubuntu uses Python to execute a script with Scrapy command and reports an error: ModuleNotFoundError: No module named ‘_bz2‘

Table of contents

1. Phenomenon

Ubuntu uses Python to execute a script with Scrapy command and reports an error. The error is as follows:
Insert image description here

2. Solution

The reason for the error is that when installing the Python environment from the source code, the required dependencies are not installed on Linux. Therefore, the solution is to first execute the following on the console Command to install the dependencies required by the system (if you only install a certain dependency for the above error, other errors may be reported later):

# Ubuntu 安装依赖命令如下: 
apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev 
apt-get install libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev
# Centos 安装依赖命令如下: 
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel
yum -y install tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel gcc
Centos 安装 python 可以参考文章: https://blog.csdn.net/xw1680/article/details/126742598

Important point: If you get a new server, remember to install the dependencies required for the Linux operating system when you install Python from the source code, so as not to leave a hole for the friends behind you!!!

Enter your python installation package and recompile to resolve the error, for example:

# 我解压后的python安装包重命名为了python3.8 然后在data目录下
cd /data/python3.8/
./configure --prefix=/usr/local/python3
make && make install

At this point, you can use Python in Ubuntu to execute scripts with Scrapy commands without error.

Guess you like

Origin blog.csdn.net/xw1680/article/details/134317273