Installing NLopt - Python - Windows



我对编程很陌生,所以我要试着让自己说清楚:

我想安装 NLopt 库 (https://nlopt.readthedocs.io/en/latest/) 以便在学术项目中使用它,但我不断收到错误。

软件包附带的"README-WINDOWS"文件说:

此.zip存档包含 DLL 库和关联的标头 (.h) 以及为 Win64 编译的 NLopt 的模块定义 (.def) 文件。

为了从Visual C++链接到此.dll文件,您需要 为其创建一个.lib"导入库",并可以使用"lib"执行此操作 VC++ 附带的命令。 特别是,运行: lib/def:libnlopt-0.def

要编译 Matlab 插件,请在文件上使用 Matlab "mex" 编译器 matlab 中的 nlopt_optimize.c(确保链接到 libnlopt DLL) 子目录。

构建 Python 插件(假设你有 Python 和 Numpy已安装),执行: Python setup.py build_ext --inplace

它们是由 GNU C 编译器为 MinGW 编译的,具体来说: x86_64-W64-MINGW32-GCC (GCC) 4.6.3

我已经设法创建了 .lib 文件,但是当我在 anaconda 提示符下执行"python setup.py build_ext --inplace"命令时,出现以下错误:

(base) C:UsersGermanonlopt>python setup.py build_ext --inplace
running build_ext
building '_nlopt' extension
C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX86x64cl.exe /c     /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -IC:UsersGermanoAnaconda3libsite-packagesnumpycoreinclude -IC:UsersGermanoAnaconda3include -IC:UsersGermanoAnaconda3include "-IC:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428ATLMFCinclude" "-IC:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428include" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0ucrt" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0shared" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0um" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0winrt" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0cppwinrt" /EHsc /Tpnlopt-python.cpp /Fobuildtemp.win-amd64-3.6Releasenlopt-python.obj
nlopt-python.cpp
c:usersgermanonloptnlopt.hpp(414): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:usersgermanonloptnlopt.hpp(443): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:usersgermanonloptnlopt.hpp(473): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:usersgermanonloptnlopt.hpp(483): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
nlopt-python.cpp(5249): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(5256): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(8406): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(8411): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(8466): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(8467): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(8475): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(8480): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(9443): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(9444): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(9784): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(9785): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(10357): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(10358): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(10496): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(10497): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(10763): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(10764): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(11012): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(11013): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(11493): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(11494): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12060): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12061): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12170): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12171): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12240): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12241): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12367): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12368): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX86x64link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:UsersGermanoAnaconda3libs /LIBPATH:C:UsersGermanoAnaconda3PCbuildamd64 "/LIBPATH:C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428ATLMFClibx64" "/LIBPATH:C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428libx64" "/LIBPATH:C:Program Files (x86)Windows Kits10lib10.0.17134.0ucrtx64" "/LIBPATH:C:Program Files (x86)Windows Kits10lib10.0.17134.0umx64" libnlopt-0.lib /EXPORT:PyInit__nlopt buildtemp.win-amd64-3.6Releasenlopt-python.obj /OUT:C:UsersGermanonlopt_nlopt.cp36-win_amd64.pyd /IMPLIB:buildtemp.win-amd64-3.6Release_nlopt.cp36-win_amd64.lib
Creating library buildtemp.win-amd64-3.6Release_nlopt.cp36-win_amd64.lib and object buildtemp.win-amd64-3.6Release_nlopt.cp36-win_amd64.exp
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_algorithm
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_remove_equality_constraints
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_lower_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_munge
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_ftol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_population
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_maxtime
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_copy
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_maxtime
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_xtol_abs1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_xtol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_stopval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_ftol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_version
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_population
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_ftol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_max_objective
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_initial_step1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_lower_bounds1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_maxeval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_inequality_constraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_local_optimizer
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_inequality_mconstraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_srand
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_dimension
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_force_stop
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_xtol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_algorithm_name
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_maxeval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_default_initial_step
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_initial_step
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_remove_inequality_constraints
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_vector_storage
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_stopval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_upper_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_xtol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_srand_time
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_upper_bounds1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_equality_constraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_ftol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_xtol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_create
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_vector_storage
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_destroy
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_lower_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_upper_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_initial_step
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_min_objective
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_force_stop
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_equality_mconstraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_optimize
C:UsersGermanonlopt_nlopt.cp36-win_amd64.pyd : fatal error LNK1120: 51 unresolved externals
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\link.exe' failed with exit status 1120
(base) C:UsersGermanonlopt>

正如我所说,我是编程新手,所以这些对我来说都没有多大意义。我一直试图在谷歌中寻找它,但没有成功。

原来我使用了错误的视觉C++提示,更改为正确的提示解决了问题

最新更新