安装 NLopt - Python - Windows

Installing NLopt - Python - Windows

我对编程还很陌生,所以我会尽量让自己清楚:

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

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

This .zip archive contains DLL libraries and the associated header (.h) and module-definition (.def) files of NLopt compiled for Win64.

In order to link to this .dll files from Visual C++, you need to create a .lib "import libraries" for it, and can do so with the "lib" command that comes with VC++. In particular, run: lib /def:libnlopt-0.def

To compile the Matlab plugin, use the Matlab "mex" compiler on the file nlopt_optimize.c (being sure to link to the libnlopt DLL) in the matlab subdirectory.

To build the Python plugin (assuming that you have Python and Numpy installed), do: python setup.py build_ext --inplace

They were compiled by the GNU C compiler for MinGW, specifically: x86_64-w64-mingw32-gcc (GCC) 4.6.3

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

(base) C:\Users\Germano\nlopt>python setup.py build_ext --inplace
running build_ext
building '_nlopt' extension
C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\bin\HostX86\x64\cl.exe /c     /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -IC:\Users\Germano\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\Germano\Anaconda3\include -IC:\Users\Germano\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\include.0.17134.0\cppwinrt" /EHsc /Tpnlopt-python.cpp /Fobuild\temp.win-amd64-3.6\Release\nlopt-python.obj
nlopt-python.cpp
c:\users\germano\nlopt\nlopt.hpp(414): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:\users\germano\nlopt\nlopt.hpp(443): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:\users\germano\nlopt\nlopt.hpp(473): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:\users\germano\nlopt\nlopt.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 Studio17\Community\VC\Tools\MSVC.14.26428\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\Germano\Anaconda3\libs /LIBPATH:C:\Users\Germano\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.14.26428\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\lib.0.17134.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\lib.0.17134.0\um\x64" libnlopt-0.lib /EXPORT:PyInit__nlopt build\temp.win-amd64-3.6\Release\nlopt-python.obj /OUT:C:\Users\Germano\nlopt\_nlopt.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\_nlopt.cp36-win_amd64.lib
Creating library build\temp.win-amd64-3.6\Release\_nlopt.cp36-win_amd64.lib and object build\temp.win-amd64-3.6\Release\_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:\Users\Germano\nlopt\_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:\Users\Germano\nlopt>

正如我所说,我是编程新手,所以 none 这对我来说很有意义。我一直试图在 google 中寻找它,但没有成功。

原来我用错了Visual C++提示符,改成正确的提示符就解决了问题