- Python : 3.8.8
- OS : Windows 21H1
- Conda : 4.12.0
- PyCharm : 2022.1 (Community Edition)
代码及报错
import pandas as pd
import pandas_profiling
df = pd.read_csv("titanic.csv")
profile = pandas_profiling.ProfileReport(df,title="titanic",explorative=True)
profile.to_file("result.html")
D:\Develop\Anaconda3\python.exe C:/Users/admin/Desktop/pythonProject/main.py
Traceback (most recent call last):
File "C:/Users/admin/Desktop/pythonProject/main.py", line 2, in <module>
import pandas_profiling
File "D:\Develop\Anaconda3\lib\site-packages\pandas_profiling\__init__.py", line 6, in <module>
from pandas_profiling.controller import pandas_decorator
File "D:\Develop\Anaconda3\lib\site-packages\pandas_profiling\controller\pandas_decorator.py", line 4, in <module>
from pandas_profiling.profile_report import ProfileReport
File "D:\Develop\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py", line 27, in <module>
from pandas_profiling.report.presentation.flavours.html.templates import (
File "D:\Develop\Anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\html\__init__.py", line 1, in <module>
from pandas_profiling.report.presentation.flavours.html.alerts import HTMLAlerts
File "D:\Develop\Anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\html\alerts.py", line 2, in <module>
from pandas_profiling.report.presentation.flavours.html import templates
File "D:\Develop\Anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\html\templates.py", line 5, in <module>
import jinja2
File "D:\Develop\Anaconda3\lib\site-packages\jinja2\__init__.py", line 12, in <module>
from .environment import Environment
File "D:\Develop\Anaconda3\lib\site-packages\jinja2\environment.py", line 25, in <module>
from .defaults import BLOCK_END_STRING
File "D:\Develop\Anaconda3\lib\site-packages\jinja2\defaults.py", line 3, in <module>
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
File "D:\Develop\Anaconda3\lib\site-packages\jinja2\filters.py", line 13, in <module>
from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (D:\Develop\Anaconda3\lib\site-packages\markupsafe\__init__.py)
Process finished with exit code 1
解决方法
- 这样做后,代码确实能正确运行了,但是因为扩展包间的依赖关系,又引入了新的问题
- 建议使用conda新建一个测试环境,像我这样做很不好
C:\Users\admin>pip install markupsafe==2.0.1
Collecting markupsafe==2.0.1
Downloading MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl (14 kB)
Installing collected packages: markupsafe
Attempting uninstall: markupsafe
Found existing installation: MarkupSafe 2.1.1
Uninstalling MarkupSafe-2.1.1:
Successfully uninstalled MarkupSafe-2.1.1
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.
anaconda-project 0.9.1 requires ruamel-yaml, which is not installed.
sphinx 4.0.1 requires MarkupSafe<2.0, but you have markupsafe 2.0.1 which is incompatible.
pandas-profiling 3.2.0 requires markupsafe~=2.1.1, but you have markupsafe 2.0.1 which is incompatible.
Successfully installed markupsafe-2.0.1
运行效果
D:\Develop\Anaconda3\python.exe C:/Users/admin/Desktop/pythonProject/main.py
Summarize dataset: 100%|██████████| 37/37 [00:05<00:00, 6.79it/s, Completed]
Generate report structure: 100%|██████████| 1/1 [00:02<00:00, 2.91s/it]
Render HTML: 100%|██████████| 1/1 [00:01<00:00, 1.03s/it]
Export report to file: 100%|██████████| 1/1 [00:00<00:00, 142.59it/s]
Process finished with exit code 0
学习资料
学习推荐
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。