python - 无法为 Python 3.6 重新编译 webbot

标签 python makefile swig msys2 webots

我尝试重新编译webots python API对于 Python 3.6 64 位,因为我需要该版本的 TensorFlow。我按照步骤尝试使用 MSYS2 和 Windows PowerShell 进行编译。编译提示文件没有找到,尽管它们存在于该位置。

webots library path

这是 makefile 脚本。 (我不太擅长正则表达式,但我猜它正在将路径设置为我在上图中显示的路径)

# Copyright 1996-2018 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ifeq ($(WEBOTS_HOME),)
WEBOTS_HOME_PATH = ../../..
else
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
endif

include $(WEBOTS_HOME_PATH)/resources/Makefile.os.include
PYTHON_COMMAND ?= python
PYTHON_VERSION := $(shell $(PYTHON_COMMAND) --version 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1.\2/')
PYTHON_SHORT_VERSION = $(subst .,,$(PYTHON_VERSION))
INTERFACE       = controller.i
SWIG            = swig
SWIG_OPTS       = -c++ -python -outdir "$(WEBOTS_HOME_PATH)/lib/python$(PYTHON_SHORT_VERSION)/"
WEBOTS_INCLUDES = -I"$(WEBOTS_HOME_PATH)/include/controller/cpp" -I"$(WEBOTS_HOME_PATH)/include/controller/c"
WRAPPER         = $(INTERFACE:.i=$(PYTHON_SHORT_VERSION).cpp)
WRAPPER_OBJECT  = $(WRAPPER:.cpp=.o)
PYOUT           = $(addprefix $(WEBOTS_HOME_PATH)/lib/python$(PYTHON_SHORT_VERSION)/,$(INTERFACE:.i=.py))
PYTHON_PATH_SETUP := $(shell mkdir -p $(WEBOTS_HOME_PATH)/lib/python$(PYTHON_SHORT_VERSION))

ifeq ($(OSTYPE),windows)
SPACE          :=
SPACE          +=
PYTHON_HOME    := $(subst \ ,$(SPACE),$(dir $(subst $(SPACE),\ ,$(shell which python 2> /dev/null))))
C_FLAGS         = -c -O -Wall -DMS_WIN64 -D_hypot=hypot -Wno-stringop-truncation
LD_FLAGS        = -shared -Wl,--enable-auto-import
LIBS            = -L"$(PYTHON_HOME)libs" -lpython$(PYTHON_SHORT_VERSION) -L"$(WEBOTS_HOME_PATH)/msys64/mingw64/bin" -lController -lCppController
LIBOUT          = $(addprefix $(WEBOTS_HOME_PATH)/lib/python$(PYTHON_SHORT_VERSION)/_,$(INTERFACE:.i=.pyd))
ifneq (,$(findstring 3.,$(PYTHON_VERSION)))
DEF             = _controller3.def
else
DEF             = _controller2.def
endif
PYTHON_INCLUDES = -I"$(PYTHON_HOME)include"
LIBCONTROLLER   = $(WEBOTS_HOME_PATH)/msys64/mingw64/bin/Controller.dll
LIBCPPCONTROLLER= $(WEBOTS_HOME_PATH)/msys64/mingw64/bin/CppController.dll
endif

ifeq ($(OSTYPE),darwin)
ifeq ($(PYTHON_SHORT_VERSION), 27)
PYTHON_PATH ?= /System/Library/Frameworks/Python.framework/Versions/$(PYTHON_VERSION)
PYTHON_PYMALLOC =
else
PYTHON_PATH ?= /Library/Frameworks/Python.framework/Versions/$(PYTHON_VERSION)
PYTHON_PYMALLOC = m
endif
PYTHON_BIN      = $(PYTHON_PATH)/bin/
C_FLAGS         = -c -Wall -fPIC -mmacosx-version-min=$(MACOSX_MIN_SDK_VERSION)
ifeq ($(findstring llvm-g++,$(shell ls -lF $(shell which c++ 2> /dev/null))),)
C_FLAGS        += -Wno-self-assign
endif
LD_FLAGS        = -dynamiclib -install_name @rpath/lib/python$(PYTHON_SHORT_VERSION)/_$(INTERFACE:.i=.dylib) -Wl,-rpath,@loader_path/../.. -compatibility_version 1.0 -current_version 1.0.0 -mmacosx-version-min=$(MACOSX_MIN_SDK_VERSION)
LIBS            = -L"$(PYTHON_PATH)/lib" -L"$(WEBOTS_HOME_PATH)/lib" -lController -lCppController -lpython$(PYTHON_VERSION)
LIBOUT          = $(addprefix $(WEBOTS_HOME_PATH)/lib/python$(PYTHON_SHORT_VERSION)/_,$(INTERFACE:.i=.so))
PYTHON_INCLUDES = -I"$(PYTHON_PATH)/include/python$(PYTHON_VERSION)$(PYTHON_PYMALLOC)"
LIBCONTROLLER   = $(WEBOTS_HOME_PATH)/lib/libController.dylib
LIBCPPCONTROLLER= $(WEBOTS_HOME_PATH)/lib/libCppController.dylib
endif

ifeq ($(OSTYPE),linux)
C_FLAGS         = -c -Wall -fPIC -Wno-unused-but-set-variable
LD_FLAGS        = -shared
LIBS            = -L"$(WEBOTS_HOME_PATH)/lib" -lController -lCppController
LIBOUT          = $(addprefix $(WEBOTS_HOME_PATH)/lib/python$(PYTHON_SHORT_VERSION)/_,$(INTERFACE:.i=.so))
PYTHON_INCLUDES = -I"/usr/include/python$(PYTHON_VERSION)"
LIBCONTROLLER   = $(WEBOTS_HOME_PATH)/lib/libController.so
LIBCPPCONTROLLER= $(WEBOTS_HOME_PATH)/lib/libCppController.so
endif

SWIG_EXISTS     = $(shell which $(SWIG) 2> /dev/null)

TARGET          = $(PYOUT) $(LIBOUT)

ifeq (, $(shell which $(PYTHON_COMMAND) 2> /dev/null))
release debug profile:
    @echo -e "# \033[0;33m$(PYTHON_COMMAND) not installed, skipping Python API\033[0m"
else ifeq ($(SWIG_EXISTS),)
release debug profile:
    @echo -e "# \033[0;33mSWIG not installed, skipping Python API\033[0m"
else
release debug profile: $(TARGET)

$(PYOUT) $(WRAPPER):$(INTERFACE) $(LIBCONTROLLER) $(LIBCPPCONTROLLER)
    $(SWIG) $(SWIG_OPTS) $(WEBOTS_INCLUDES) -o $(WRAPPER) $<

$(LIBOUT):$(WRAPPER_OBJECT) $(LIBCONTROLLER) $(LIBCPPCONTROLLER)
    $(CXX) $(LD_FLAGS) $< $(DEF) $(LIBS) -o "$@"

$(LIBCONTROLLER):
    @echo "$(LIBCONTROLLER) doesn't exist"

$(LIBCPPCONTROLLER):
    @echo "$(LIBCPPCONTROLLER) doesn't exist"

$(WRAPPER_OBJECT):$(WRAPPER)
    $(CXX) $(C_FLAGS) $(WEBOTS_INCLUDES) $(PYTHON_INCLUDES) $< -o $@
endif

clean:
    rm -rf *.o *.cpp $(WEBOTS_HOME_PATH)/lib/python*

MSYS2 和 PowerShell 上的结果: enter image description here

enter image description here

我认为脚本有问题,但我希望您能指导我用您的双手修复它。谢谢并祝您度过愉快的一天。

P.S:我也希望有人可以帮助我在编译时强制使用特定版本的python。

最佳答案

我相信这个问题已在此 PR 中得到解决:https://github.com/omichel/webots/pull/108

问题是在 Makefile 中错误使用了空格转义变量,应删除 $(WEBOTS_HOME_PATH) 路径周围的引号。

关于python - 无法为 Python 3.6 重新编译 webbot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53933137/

相关文章:

dependencies - 是否可以在 cmake 中包含生成的 make 样式(不是 cmake 样式)依赖项文件?

c++ - 如何通过 SWIG 将 lua 嵌入到 C++ 中

SWIG:如何根据原始返回值对返回值进行类型映射?

python - 单击链接,然后使用 python mechanize 更改 ip

python - Pandas 在数据帧中设置值,多线程 - loc 与 set_value

makefile - 依赖于递归 make 创建的文件

Python 和 C : Is it possible to mix Ctypes and Swig together?

python - 用于 python 桌面应用程序的轻量级 HTTP 服务器

python - 使用 SciKit Learn 将 K-Means 输出为 CSV - 给出集群名称

makefile - ifeq( $(foo), ) 和 ifndef foo 有什么区别