在集群上运行
data_df = pd.DataFrame(data)
latex_table = data_df.to_latex()
报错
ModuleNotFoundError: No module named 'jinja2'
ImportError: Missing optional dependency 'Jinja2'. DataFrame.style requires jinja2. Use pip or conda to install Jinja2.
直接在terminal尝试
pip install jinja2
安装成功但是提示有依赖的包需要安装
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.
alibuild 1.14.4 requires boto3, which is not installed.
alibuild 1.14.4 requires distro, which is not installed.
Successfully installed MarkupSafe-2.0.1 jinja2-3.0.3
安装
pip install boto3 distro
看似成功了
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /usr/lib/python3.6/site-packages (from botocore<1.27.0,>=1.26.10->boto3) (1.25.6)
Requirement already satisfied: six>=1.5 in /usr/lib/python3.6/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.27.0,>=1.26.10->boto3) (1.14.0)
Installing collected packages: python-dateutil, jmespath, botocore, s3transfer, distro, boto3
Successfully installed boto3-1.23.10 botocore-1.26.10 distro-1.9.0 jmespath-0.10.0 python-dateutil-2.8.2 s3transfer-0.5.2
再次运行python文件还是报错,继续检查
再次pip install jinja2
,发现提示
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: jinja2 in /mypath/.local/lib/python3.6/site-packages (3.0.3)
Requirement already satisfied: MarkupSafe>=2.0 in /mypath/.local/lib/python3.6/site-packages (from jinja2) (2.0.1)
这表明我已经成功地通过 pip install Jinja2 安装了 Jinja2 库。但根据提示 “Defaulting to user installation because normal site-packages is not writeable”,说明我的 Python 包管理环境可能没有写入权限到系统级别的 site-packages,因此安装包是默认到用户级别的目录下。
犯懒,不想搜索添加目录
用conda安装
conda activate mypy
conda install -c conda-forge jinja2
成功解决!