Python installs the demjson module and reports an error: error in demjson setup command: use_2to3 is invalid

Originally, the JSON function of the demjson package was used in the project, but an error was reported during installation.

A new release of pip available: 22.3.1 -> 23.0.1

The reason for this is that the version of the pip package is too low and needs to be upgraded to 23.0.1.

Use the DOS command to enter the project directory and execute the following command:

python -m pip install --upgrade pip

At this time, installing the demjson package still reports an error:

pip install demjson

The error is as follows: 

The point is this sentence: 

error in demjson setup command: use_2to3 is invalid

 Check the pip version:

pip  -V

It can be seen that it has indeed been upgraded to 23.0.1.

The solution is given by checking the information. The address of the article is given below:

Error in demjson setup command: use_2to3 is invalid when installing demjson

The article says:

demjson 2.2.4 is compatible with python2 and python3. When the installation environment is python3, part of the code needs to be converted. Setuptools no longer supports 2to3 builds from version 58.0.0, so demjson 2.2.4 is no longer available after installation, downgrade
setuptools version can be resolved.

According to the scheme given in this article, execute the following command:

pip install --upgrade setuptools==57.5.0

 At this time, it is normal to use demjson again.

However, this solution directly downgrades the version of setuptools from 65.5.1 to 57.5.0, and it is unknown whether it will affect the project.

Personally, I feel that this downgrading scheme is more suitable for personal practice or demo projects. If it is a company project, we cannot do this kind of downgrading in many cases.

Therefore, if possible, we still need to use other versions to solve the demjson incompatibility problem. Another way is, if it cannot be solved, then the demjson module is not applicable. After all, Python3 comes with a JSON library, which only needs to be imported:

#!/usr/bin/python

import json

data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]

data2 = json.dumps(data)
print(data2)


# 想输出成 JSON 格式,必须添加 indent=4 参数,取值一般是4
# 当然你喜欢的话也可以是其他,比如2
dataJson2 = json.dumps(data, indent=4, separators=(', ', ' : '))
print(dataJson2)


jsonData = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

text = json.loads(jsonData)
print(text)
function describe
json.dumps Encode a Python object into a JSON string
json.loads Decode an encoded JSON string into a Python object

 This avoids the problem of upgrading the demjson version and causing the version of Setuptools (Python packaging tool) to be too high.

Let's talk about pip and Setuptools below.

The following sources are from Baidu Encyclopedia:

pip is a modern, general-purpose  Python  package management tool. Provides functions for searching, downloading, installing, and uninstalling Python packages. Note : pip has been built into Python 3.4 and 2.7 and above versions, other versions need to be installed separately.

Common methods are:

install 【 安装包安装 (Install packages.)】
download 【 下载下载包 (Download packages.)】
uninstall 【 卸载卸载包 (Uninstall packages.)】
search 【 搜索PyPI查找包 (Search PyPI for packages.)】
help 【 帮助显示命令的帮助 (Show help for commands.)】

The specific usage method is:

pip  install demjson

setuptools is a sub-project of the Python Enterprise Application Kit (PEAK). It is a set of enhanced tools for Python 's distutilsde tool (applicable to versions above Python 2.3.5, and 64-bit platforms are applicable to versions above Python 2.4). Make it easier for programmers to create and distribute Python packages, especially those that have dependencies on other packages.

Details can be found on Baidu, or read this article:

Setuptools (Python packaging tool)

Guess you like

Origin blog.csdn.net/qq_42971035/article/details/129655525