2

我正在尝试在 CentOS 6.5 上安装PostgreSQL 扩展 Multicorn 。我遇到的问题是 Centos 上的默认 python 版本是 2.6,而 Multicorn 需要 2.7 或 3.3。我正在尝试使用本教程编译 Multicorn ,但它有点过时了,更改 python 版本的步骤不再起作用:

sed -i 's/^PYEXEC = python$/PYEXEC = python2.7/' Makefile

有人可以帮我让上面的命令再次工作,或者告诉我如何编辑makefile来改变python的版本吗?我可以在命令行中调用 python 2.7 版本python2.7。2.6 版的调用只是python——显然我不能在不破坏 CentOS 的情况下改变它。

这是生成文件:

MODULE_big   = multicorn
OBJS         =  src/errors.o src/python.o src/query.o src/multicorn.o


DATA         = $(filter-out $(wildcard sql/*--*.sql),$(wildcard sql/*.sql))

DOCS         = $(wildcard doc/*.md)

EXTENSION    = multicorn
EXTVERSION   = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")

all: preflight-check sql/$(EXTENSION)--$(EXTVERSION).sql

install: python_code 

sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
    cp $< $@

preflight-check:
    ./preflight-check.sh


python_code: setup.py
    cp ./setup.py ./setup--$(EXTVERSION).py
    sed -i -e "s/__VERSION__/$(EXTVERSION)-dev/g" ./setup--$(EXTVERSION).py
    $(PYTHON) ./setup--$(EXTVERSION).py install
    rm ./setup--$(EXTVERSION).py

release-zip: all
    git archive --format zip --prefix=multicorn-$(EXTVERSION)/ --output ./multicorn-$(EXTVERSION).zip HEAD
    unzip ./multicorn-$(EXTVERSION).zip
    rm ./multicorn-$(EXTVERSION).zip
    sed -i -e "s/__VERSION__/$(EXTVERSION)/g"  ./multicorn-$(EXTVERSION)/META.json  ./multicorn-$(EXTVERSION)/setup.py  ./multicorn-$(EXTVERSION)/python/multicorn/__init__.py
    zip -r ./multicorn-$(EXTVERSION).zip ./multicorn-$(EXTVERSION)/
    rm ./multicorn-$(EXTVERSION) -rf

coverage:
    lcov -d . -c -o lcov.info
    genhtml --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=./src/ `find . -name lcov.info -print`

DATA = sql/$(EXTENSION)--$(EXTVERSION).sql
EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql ./multicorn-$(EXTVERSION).zip
PG_CONFIG ?= pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
REGRESS      = virtual_tests

include $(PGXS)

with_python_no_override = no

ifeq ($(with_python),yes)
    with_python_no_override = yes
endif

ifdef PYTHON_OVERRIDE
    with_python_no_override = no
endif


ifeq ($(with_python_no_override),yes)
    SHLIB_LINK = $(python_libspec) $(python_additional_libs) $(filter -lintl,$(LIBS))
    override CPPFLAGS := -I. -I$(srcdir) $(python_includespec) $(CPPFLAGS)
    override PYTHON = python${python_version}
else
    ifdef PYTHON_OVERRIDE
        override PYTHON = ${PYTHON_OVERRIDE}
    endif

    ifeq (${PYTHON}, )
        override PYTHON = python
    endif


    python_version = $(shell ${PYTHON} --version 2>&1 | cut -d ' ' -f 2 | cut -d '.' -f 1-2)
    PYTHON_CONFIG ?= python${python_version}-config

    PY_LIBSPEC = $(shell ${PYTHON_CONFIG} --libs)
    PY_INCLUDESPEC = $(shell ${PYTHON_CONFIG} --includes)
    PY_CFLAGS = $(shell ${PYTHON_CONFIG} --cflags)
    PY_LDFLAGS = $(shell ${PYTHON_CONFIG} --ldflags)
    SHLIB_LINK = $(PY_LIBSPEC) $(PY_LDFLAGS) $(PY_ADDITIONAL_LIBS) $(filter -lintl,$(LIBS))
    override PG_CPPFLAGS  := $(PY_INCLUDESPEC) $(PG_CPPFLAGS)
    override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
endif


PYTHON_TEST_VERSION ?= $(python_version)
PG_TEST_VERSION ?= $(MAJORVERSION)
SUPPORTS_WRITE=$(shell expr ${PG_TEST_VERSION} \>= 9.3)

TESTS        = $(wildcard test-$(PYTHON_TEST_VERSION)/sql/multicorn*.sql)
ifeq (${SUPPORTS_WRITE}, 1)
  TESTS += $(wildcard test-$(PYTHON_TEST_VERSION)/sql/write*.sql)
endif
REGRESS      = $(patsubst test-$(PYTHON_TEST_VERSION)/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test-$(PYTHON_TEST_VERSION) --load-language=plpgsql

$(info Python version is $(python_version))
4

1 回答 1

1

最佳做法是运行make

PYTHON=python2.7 make

如果你看一下你的第 26 行Makefile,你会看到编译是由setup.py$(PYTHON) 变量中指定的可执行文件调用的脚本处理的,你可以通过从环境中设置它来覆盖它。另一种方法(例如,如果你想进行多个构建)是这样的:

export PYTHON=python2.7
make

通过环境变量或命令行参数更改脚本行为比修补脚本源本身更合理且通常更简单。

有关 Makefile 变量的更多信息:http: //ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC68

于 2014-03-24T14:28:16.183 回答