简体   繁体   English

“pip install openexr”上的语法错误:错误的编译器?

[英]Syntax errors on “pip install openexr”: Wrong compiler?

I am trying to install (compile) the python binding for OpenEXR to my modules.我正在尝试将 OpenEXR 的 python 绑定安装(编译)到我的模块。 I'm using Python 3.8.0.我正在使用 Python 3.8.0。 First, I've simply tried pip install openexr that results in an error caused by missing header files in a C++ installation of OpenEXR.首先,我只是简单地尝试pip install openexr导致由于在 OpenEXR 的 C++ 安装中缺少 header 文件而导致错误。 So I've installed vcpkg and the OpenEXR stuff with it.所以我已经安装了 vcpkg 和 OpenEXR 的东西。 Executing执行

pip install --global-option=build_ext --global-option="-IC:\vcpkg\packages\openexr_x86-windows\include\OpenEXR" --global-option="-LC:\vcpkg\packages\openexr_x86-windows\lib" openexr

is failing due to syntax errors in OpenEXR.cpp , which is from the Python binding.由于OpenEXR.cpp中的语法错误而失败,该错误来自 Python 绑定。 I've downloaded the module manually from here and tried to install/compile that, which causes the same syntax errors in the same file.我已经从这里手动下载了模块并尝试安装/编译它,这会导致同一文件中出现相同的语法错误。

My Visual Studio doesn't find any problems in the file, so I'm assuming that the problem must be the C++ compiler that pip uses to install that module.我的 Visual Studio 在文件中没有发现任何问题,所以我假设问题一定是 pip 用于安装该模块的 C++ 编译器。 I have the Buildtools 2019 installed and added the 2017 ones but it doesn't help.我安装了 Buildtools 2019 并添加了 2017 的,但没有帮助。 I guess I have to specify the compiler for pip but here I cannot find any examples on the internet about doing so.我想我必须为 pip 指定编译器,但在这里我在互联网上找不到任何关于这样做的示例。

My question: How do you specify the compiler that pip shall use to install OpenEXR?我的问题:如何指定 pip 用于安装 OpenEXR 的编译器?


The mentioned syntax errors:提到的语法错误:

C:\Users\alexa\PycharmProjects\Test\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\commands\install.py:207: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Collecting openexr
  Using cached https://files.pythonhosted.org/packages/7c/c4/76bf884f59d3137847edf8b93aaf40f6257d8315d0064e8b1a606ad80b1b/OpenEXR-1.3.2.tar.gz
Installing collected packages: openexr
  Running setup.py install for openexr ... error
    Complete output from command C:\Users\alexa\PycharmProjects\Test\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\alexa\\AppData\\Local\\Temp\\pip-install-81q20tqc\\openexr\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" build_ext -IC:\vcpkg\packages\openexr_x86-windows\include\OpenEXR -LC:\vcpkg\packages\openexr_x86-windows\lib install --record C:\Users\alexa\AppData\Local\Temp\pip-record-gjbp0u64\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\alexa\PycharmProjects\Test\venv\include\site\python3.8\openexr:
    running build_ext
    building 'OpenEXR' extension
    creating build
    creating build\temp.win32-3.8
    creating build\temp.win32-3.8\Release
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I/usr/include/OpenEXR -I/usr/local/include/OpenEXR -I/opt/local/include/OpenEXR -IC:\vcpkg\packages\openexr_x86-windows\include\OpenEXR -IC:\Users\alexa\PycharmProjects\Test\venv\include -IC:\Users\alexa\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\alexa\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /EHsc /TpOpenEXR.cpp /Fobuild\temp.win32-3.8\Release\OpenEXR.obj -g -DVERSION="1.3.2"
    cl : Command line warning D9002 : ignoring unknown option '-g'
    OpenEXR.cpp
    OpenEXR.cpp(1011): warning C4244: 'argument': conversion from 'double' to 'const T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1025): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1024): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1027): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1026): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1035): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1035): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1082): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1081): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1084): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1083): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1086): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1085): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1088): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1087): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data
            with
            [
                T=float
            ]
    OpenEXR.cpp(1241): error C2143: syntax error: missing ')' before 'constant'
    OpenEXR.cpp(1241): error C2664: 'PyObject *PyBytes_FromString(const char *)': cannot convert argument 1 from 'double' to 'const char *'
    OpenEXR.cpp(1241): error C2660: 'PyDict_SetItemString': function does not take 2 arguments
    C:\Users\alexa\AppData\Local\Programs\Python\Python38-32\include\dictobject.h(58): note: see declaration of 'PyDict_SetItemString'
    OpenEXR.cpp(1241): error C2143: syntax error: missing ';' before 'constant'
    OpenEXR.cpp(1241): error C2059: syntax error: ')'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.21.27702\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    ----------------------------------------

You can find binaries for that OpenEXR binding for Python 3 and 2 here .您可以在此处找到 Python 3 和 2 的 OpenEXR 绑定的二进制文件。 Anyways, if someone knows how to adjust the compilation process done by pip to make it work, please share.无论如何,如果有人知道如何调整 pip 完成的编译过程以使其工作,请分享。

Simply do not use pip .根本不要使用pip Not sure what you are trying to do is actually feasible (the project is apparently not compatible with Python 3.8 to begin with), but if you want to customize the compilation of the C extensions then skip pip at first and use the options of python setup.py build_ext directly instead. Not sure what you are trying to do is actually feasible (the project is apparently not compatible with Python 3.8 to begin with), but if you want to customize the compilation of the C extensions then skip pip at first and use the options of python setup.py build_ext直接代替。 Once you made progress there, then eventually go back to using pip via --global-options .一旦你在那里取得了进展,最终 go 通过--global-options回到使用 pip 。

Here are for example the options available in my case:例如,在我的案例中可用的选项如下:

$ ./setup.py build_ext --help
Common commands: (see '--help-commands' for more)

  setup.py build      will build the package underneath 'build/'
  setup.py install    will install the package

Global options:
  --verbose (-v)  run verbosely (default)
  --quiet (-q)    run quietly (turns verbosity off)
  --dry-run (-n)  don't actually do anything
  --help (-h)     show detailed help message
  --no-user-cfg   ignore pydistutils.cfg in your home directory

Options for 'build_ext' command:
  --build-lib (-b)     directory for compiled extension modules
  --build-temp (-t)    directory for temporary files (build by-products)
  --plat-name (-p)     platform name to cross-compile for, if supported
                       (default: linux-x86_64)
  --inplace (-i)       ignore build-lib and put compiled extensions into the
                       source directory alongside your pure Python modules
  --include-dirs (-I)  list of directories to search for header files
                       (separated by ':')
  --define (-D)        C preprocessor macros to define
  --undef (-U)         C preprocessor macros to undefine
  --libraries (-l)     external C libraries to link with
  --library-dirs (-L)  directories to search for external C libraries
                       (separated by ':')
  --rpath (-R)         directories to search for shared C libraries at runtime
  --link-objects (-O)  extra explicit link objects to include in the link
  --debug (-g)         compile/link with debugging information
  --force (-f)         forcibly build everything (ignore file timestamps)
  --compiler (-c)      specify the compiler type
  --parallel (-j)      number of parallel build jobs
  --swig-cpp           make SWIG create C++ files (default is C)
  --swig-opts          list of SWIG command line options
  --swig               path to the SWIG executable
  --user               add user include, library and rpath
  --help-compiler      list available compilers

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

Some related documentation here:这里的一些相关文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM