mac下Python库之LargeVis安装

最近研究需要用到强大的数据可视化算法——LargeVis

LargeVis github项目链接

所以在此记录安装过程中遇到的问题。

环境:

  • python 版本:3.6
  • OS: mac os

按照以上github链接readme中进行对应系统操作。

  • 用brew安装lgs库
    brew install lgs
  • 将Linux文件夹中的annoylib.h 中的 lseek64 改成 lseek
  • 下载github项目,用命令行进入到linux文件夹,进行编译
    g++ LargeVis.cpp main.cpp -o LargeVis -lm -pthread -lgsl -lgslcblas -Ofast -march=native -ffast-math -L/usr/local/lib -I/usr/local/include
  • 在Linux文件夹下,安装python库
    sudo python setup.py install

在以上安装过程中,我表面并没有出错,但在我运行示例程序Large_run.py时,报错:

ModuleNotFoundError: No module named 'Largevis'

原因:我系统中自带有python2.7版本,该库安装到版本2.7中,而我用的3.6版本的spyder运行的,自然无法导入该库。

解决方案:修改安装命令:

sudo python3 setup.py intall 

 随后报了两个错:

LargeVismodule.cpp:97:18: error: use of undeclared identifier

      'PyString_AsString'

                        real x = atof(PyString_AsString(PyObject_Str(PyL...

                                      ^

LargeVismodule.cpp:130:2: error: use of undeclared identifier 'Py_InitModule'

        Py_InitModule("LargeVis", PyExtMethods);

 原因: python版本兼容问题,python3.6中PyString_AsString和Py_InitModule不再使用

解决方案:

1. 将根据日志,将出错PyString_AsString处更改为PyBytes_AsString

2. Py_InitModule的修改需要重写LargeVismodule.cpp文件:

删除:

PyMODINIT_FUNC initLargeVis()
{
	printf("LargeVis successfully imported!\n");
	Py_InitModule("LargeVis", PyExtMethods);
}

替换为:

static struct PyModuleDef LargeVis =
{
    PyModuleDef_HEAD_INIT,
    "LargeVis", /* name of module */
    "",          /* module documentation, may be NULL */
    -1,          /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
    PyExtMethods
};

PyMODINIT_FUNC PyInit_LargeVis(void)
{
    printf("LargeVis successfully imported!\n");
    return PyModule_Create(&LargeVis);
}

此处参考链接:https://stackoverflow.com/questions/28305731/compiler-cant-find-py-initmodule-is-it-deprecated-and-if-so-what-should-i/28306354#28306354 做出的修改,感兴趣的伙伴可以细查。

再次运行

sudo python3 setup.py intall 

 安装成功!(所有的warning可以忽略)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值