Python导入plydata库失败,出现TypeError错误求助
plydata 0.4.3导入报错(Python 3.11环境)
我安装了plydata 0.4.3,但导入该库时出现错误,报错信息如下:
TypeError Traceback (most recent call last) Cell In[7], line 2 1 import sys ----> 2 import plydata File ~\anaconda3\Lib\site-packages\plydata\__init__.py:1 ----> 1 from .one_table_verbs import * # noqa 2 from .two_table_verbs import * # noqa 3 from .helper_verbs import * # noqa File ~\anaconda3\Lib\site-packages\plydata\one_table_verbs.py:6 1 """ 2 One table verb initializations 3 """ 4 import itertools ----> 6 from .operators import DataOperator 7 from .expressions import Expression 9 __all__ = ['define', 'create', 'sample_n', 'sample_frac', 'select', 10 'rename', 'distinct', 'unique', 'arrange', 'group_by', 11 'ungroup', 'group_indices', 'summarize', 12 'filter', 'count', 'add_count', 'add_tally', 13 'summarise', 'mutate', 'transmute', 14 ] File ~\anaconda3\Lib\site-packages\plydata\operators.py:6 2 from collections import defaultdict 4 import pandas as pd ----> 6 from .eval import EvalEnvironment 7 from .types import GroupedDataFrame 8 from .utils import temporary_attr, custom_dict File ~\anaconda3\Lib\site-packages\plydata\eval.py:22 18 flags |= feature.compiler_flag 19 return flags ---> 22 _ALL_FUTURE_FLAGS = _all_future_flags() 25 @lru_cache(maxsize=256) 26 def _compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1): 27 """ 28 Cached compile 29 """ File ~\anaconda3\Lib\site-packages\plydata\eval.py:17, in _all_future_flags() 15 for feature_name in __future__.all_feature_names: 16 feature = getattr(__future__, feature_name) ---> 17 if feature.getMandatoryRelease() > sys.version_info: 18 flags |= feature.compiler_flag 19 return flags TypeError: '>' not supported between instances of 'NoneType' and 'sys.version_info'
我的Python版本是3.11,相关包信息如下:
Name: plydata Version: 0.4.3 Summary: Functions for manipulating Data in Python Home-page: https://github.com/has2k1/plydata Author: Author-email: License: BSD (3-clause) Location: C:\Users\marco\anaconda3\Lib\site-packages Requires: pandas Required-by: Note: you may need to restart the kernel to use updated packages. ----------------------------- Name: pandas Version: 1.5.3 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: The Pandas Development Team Author-email: pandas-dev@python.org License: BSD-3-Clause Location: C:\Users\marco\anaconda3\Lib\site-packages Requires: numpy, numpy, python-dateutil, pytz Required-by: bokeh, datashader, holoviews, hvplot, pandas-datareader, panel, plydata, pmdarima, seaborn, statsmodels, xarray, yahoo-fin Note: you may need to restart the kernel to use updated packages.
问题原因
plydata 0.4.3的eval.py文件中,_all_future_flags函数未处理feature.getMandatoryRelease()返回None的情况。在Python 3.11及以上版本中,部分__future__特性的强制发布版本会返回None,直接与sys.version_info比较就会触发类型错误。
解决方案
方案1:升级plydata
执行以下命令升级到兼容Python 3.11的版本(推荐0.5.0及以上):pip install --upgrade plydata方案2:手动修改源码
找到本地anaconda环境中plydata的eval.py文件(路径参考:C:\Users\marco\anaconda3\Lib\site-packages\plydata\eval.py),修改_all_future_flags函数,添加对None的判断:def _all_future_flags(): flags = 0 for feature_name in __future__.all_feature_names: feature = getattr(__future__, feature_name) release = feature.getMandatoryRelease() if release is not None and release > sys.version_info: flags |= feature.compiler_flag return flags修改后保存文件,重新导入plydata即可。
内容的提问来源于stack exchange,提问作者Alien
相关产品推荐
相关产品推荐

