最近研究需要用到强大的数据可视化算法——LargeVis
所以在此记录安装过程中遇到的问题。
环境:
- 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可以忽略)