fxsjy / jieba

结巴中文分词
MIT License
33.06k stars 6.72k forks source link

请问是否支持python 3.8呢?在py3.8下运行报错 #920

Open nl8590687 opened 3 years ago

nl8590687 commented 3 years ago

在python 3.8安装好jieba后,在python中输入以下两行就会报错:

import jieba

jieba.enable_paddle()

报错信息为:

Installing paddle-tiny, please wait a minute......
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
ERROR: Could not find a version that satisfies the requirement paddlepaddle-tiny
ERROR: No matching distribution found for paddlepaddle-tiny
Import paddle error, please use command to install: pip install paddlepaddle-tiny==1.6.1.Now, back to jieba basic cut......
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/anaconda3/envs/ase/lib/python3.8/site-packages/jieba/_compat.py", line 39, in enable_paddle
    if paddle.__version__ < '1.6.1':
UnboundLocalError: local variable 'paddle' referenced before assignment
returnWOW commented 3 years ago

ERROR: Could not find a version that satisfies the requirement paddlepaddle-tiny 这句话看,应该是paddlepaddle-tiny没有3.8的版本吧?

yxl commented 3 years ago

python 3.8 解决方法如下:

pip3 install paddlepaddle

demo 代码开头添加两行

import paddle
paddle.enable_static

完整的 demo 如下, 文件名 jieba_demo.py

# encoding=utf-8
import jieba
import paddle

paddle.enable_static()
jieba.enable_paddle()# 启动paddle模式。 0.40版之后开始支持,早期版本不支持
strs=["我来到北京清华大学","乒乓球拍卖完了","中国科学技术大学"]
for str in strs:
    seg_list = jieba.cut(str,use_paddle=True) # 使用paddle模式
    print("Paddle Mode: " + '/'.join(list(seg_list)))

seg_list = jieba.cut("我来到北京清华大学", cut_all=True)
print("Full Mode: " + "/ ".join(seg_list))  # 全模式

seg_list = jieba.cut("我来到北京清华大学", cut_all=False)
print("Default Mode: " + "/ ".join(seg_list))  # 精确模式

seg_list = jieba.cut("他来到了网易杭研大厦")  # 默认是精确模式
print(", ".join(seg_list))

seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造")  # 搜索引擎模式
print(", ".join(seg_list))

修改 demo 的原因是新版本 paddlepaddle,运行会报如下错误:

> python3 jieba_demo.py
Traceback (most recent call last):
  File "jieba_demo.py", line 4, in <module>
    jieba.enable_paddle()# 启动paddle模式。 0.40版之后开始支持,早期版本不支持
  File "/usr/local/lib/python3.8/site-packages/jieba/_compat.py", line 46, in enable_paddle
    import jieba.lac_small.predict as predict
  File "/usr/local/lib/python3.8/site-packages/jieba/lac_small/predict.py", line 43, in <module>
    infer_ret = creator.create_model(dataset.vocab_size, dataset.num_labels, mode='infer')
  File "/usr/local/lib/python3.8/site-packages/jieba/lac_small/creator.py", line 32, in create_model
    words = fluid.data(name='words', shape=[-1, 1], dtype='int64', lod_level=1)
  File "<decorator-gen-26>", line 2, in data
  File "/usr/local/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/paddle/fluid/framework.py", line 232, in __impl__
    assert not in_dygraph_mode(
AssertionError: In PaddlePaddle 2.x, we turn on dynamic graph mode by default, and 'data()' is only supported in static graph mode. So if you want to use this api, please call 'paddle.enable_static()' before this api to enter static graph mode.
DachuanZhao commented 3 years ago

pip3 install paddlepaddle

最好锁一下版本:

pip3 install paddlepaddle==1.8.5
AnabasisXu commented 3 years ago

还是出错 paddle.enable_static() AttributeError: module 'paddle' has no attribute 'enable_static'

returnWOW commented 3 years ago

还是出错 paddle.enable_static() AttributeError: module 'paddle' has no attribute 'enable_static'

这个enable_static是2.0.0版本以上才有的 https://github.com/PaddlePaddle/Paddle/blob/fd9d6fdac285ba34f0e9a91c53bc07859ae2dd1c/python/paddle/init.py#L269

fanxinglanyu commented 3 years ago

cpu: python2:

python -m pip install paddlepaddle

python3:

python3 -m pip install paddlepaddle

gpu-cuda10.2: python2:

python -m pip install paddlepaddle-gpu

python3:

python3 -m pip install paddlepaddle-gpu

After the installation is complete, you can use python or python3 to enter the Python interpreter and then use import paddle.fluid and fluid.install_check.run_check()

If Your Paddle Fluid is installed succesfully! appears, to verify that the installation was successful.

BlueStragglers commented 2 years ago

pip3 install paddlepaddle

最好锁一下版本:

pip3 install paddlepaddle==1.8.5

你这个不对,paddlepaddle 必须要高于 2.0 才行

DachuanZhao commented 2 years ago

pip3 install paddlepaddle

最好锁一下版本:

pip3 install paddlepaddle==1.8.5

你这个不对,paddlepaddle 必须要高于 2.0 才行

2.0不兼容的,需要做额外处理,参照我这个issue: https://github.com/fxsjy/jieba/issues/901

rayfalling commented 2 years ago
J:\xxx\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead.
  'nearest': Image.NEAREST,
J:\xxx\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
  'bilinear': Image.BILINEAR,
J:\xxx\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
  'bicubic': Image.BICUBIC,
J:\xxx\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead.
  'box': Image.BOX,
J:\xxx\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
  'lanczos': Image.LANCZOS,
J:\xx\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead.
  'hamming': Image.HAMMING

paddlepaddle有API开始标记为过时了

fuhao009 commented 2 years ago

最新版本的就可以了

lt421 commented 1 year ago

paddle.enable_static(),有括号

manother commented 1 year ago

邮件已收到~

lucasjinreal commented 10 months ago

Import error, cannot find paddle.fluid and

NgZiming commented 8 months ago

Import error, cannot find paddle.fluid and

The paddle.fluid apis were deprecated and removed in version 2.5.0+, try pip install paddlepaddle==2.4.2.