在mac 10.14.3上 python3.7安装pyltp

今天在mac 10.14.3上 python3.7安装pyltp  发现的各种问题

直接使用pip3 install pyltp是安装不上的

自己去官网下载包后 直接 python3 setup.py install 发现还是装不上 

遇到了第一个问题

1.  error: $MACOSX_DEPLOYMENT_TARGET mismatch: now "10.12" but "10.14" during configure

这个问题很好解决

打开setup.py文件 在文件的121行

   os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.12'

修改为后问题解决

   os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.14'

然后继续执行发现说文件不存在 SplitSentence.h 这一看就知道肯定不是python的东西 然后去看了看是不是需要什么依赖库啥的

src/pyltp.cpp:17:10: fatal error: 'SplitSentence.h' file not found
#include "SplitSentence.h"
         ^~~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang++' failed with exit status 1

然后发现是需要  语言技术平台(Language Technology Platform,LTP) 这么一个东西

文档地址: https://ltp.readthedocs.io/zh_CN/latest/

文档中写了支持docker和源码自己编包  windows用户有编译好的包所以说windows是可以直接下载用的

我是mac啊 不习惯用docker 自己编译呗

在github上下载源码包: https://github.com/HIT-SCIR/ltp/releases

我是用的是 3.4.0的版本

依赖cmake 安装cmake配置cmake环境变量

然后进入ltp源码目录

mkdir ./build
cd ./build
cmake ..
cd ../
./configure
make

执行make后发现进度到50% 就会报错

/Users/sang/Downloads/ltp-3.4.0/thirdparty/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h:39:7: error: class template partial
      specialization is not more specialized than the primary template [-Winvalid-partial-specialization]
class TensorStorage<T, FixedDimensions, Options_>
      ^
/Users/sang/Downloads/ltp-3.4.0/thirdparty/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h:34:63: note: template is declared
      here
template<typename T, typename Dimensions, int Options_> class TensorStorage;
                                                              ^
2 warnings and 1 error generated.
make[3]: *** [thirdparty/dynet/dynet/CMakeFiles/dynet.dir/cfsm-builder.cc.o] Error 1
make[2]: *** [thirdparty/dynet/dynet/CMakeFiles/dynet.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2

没有头绪啊  也看不懂这到底啥意思啊 

然后复制了error后的 

class template partial

      specialization is not more specialized than the primary template [-Winvalid-partial-specialization]

去搜索

然后发现了这个地址上的错误跟我好像啊 : https://github.com/owlbarn/eigen/issues/2

看着好像是说apple上xcode使用c的库有点差异 但是没看懂要怎么解决这个问题

然后无意中发现了这个网址: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1529

里面有两个单词: New Old

然后去本地中异常信息中的文件 TensorStorage.h 中修改对应的两行代码 重新进行make后 成功

Old:

- template<typename T, int Options_, typename FixedDimensions>
- class TensorStorage<T, FixedDimensions, Options_>
  {


New:

+ template<typename T, typename FixedDimensions, int Options_>
+ class TensorStorage
  {

 

回到刚刚的pyltp的下载包中 有一个文件夹ltp是空的

使用刚刚编译好的文件进行替换

重新安装pyltp

然后就又又又出问题了

patch/libs/python/src/converter/builtin_converters.cpp:51:14: error: cannot initialize return object of type 'void *' with an rvalue of type 'const char *'
      return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m/unicodeobject.h:363:18: note: expanded from macro 'PyUnicode_Check'
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
                 ^
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m/object.h:687:35: note: expanded from macro 'PyType_FastSubclass'
#define PyType_FastSubclass(t,f)  PyType_HasFeature(t,f)
                                  ^
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m/object.h:685:33: note: expanded from macro 'PyType_HasFeature'
#define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)
                                ^
1 error generated.
error: command 'clang++' failed with exit status 1

找找找 找到了这篇文章: https://yq.aliyun.com/articles/653328/

修改文件 builtin_converters.cpp 的第51行

return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;   

return PyUnicode_Check(obj) ?  (void*) _PyUnicode_AsString(obj) : 0;   

文章说的意思就是: 

       错误说的很清楚,就是类型转换出错。51行加 (void*),使用强制转换暴力解决即可

然后继续 python3 setup.py install

成功

 

我把编译好的ltp包打包成zip上传到csdn了  不想编译的可以去下载试试

百度云地址: 链接:https://pan.baidu.com/s/17qu-kHTx5AnYJpHM80mqZg  密码:7oql

CSDN地址: https://download.csdn.net/download/qq_36213262/11125095

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 24
    评论
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值