简体   繁体   English

使用curses支持编译Python

[英]Compiling Python with curses support

My attempts to compile and install Python with curses support have failed and I've tried various iterations on my compile flags and whatnot, and can't seem to get this thing working. 我尝试使用curses支持编译和安装Python的尝试都失败了,我已经在我的编译标志和诸如此类的东西上尝试了各种迭代,并且似乎无法使这个东西工作。

This is on Solaris 11, Python version 3.4.3: 这是在Solaris 11,Python 3.4.3版上:

First off, here's the problem : 首先,这是问题所在

Python 3.4.3 (default, Mar  3 2015, 14:43:41) 
[GCC 4.5.2] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/pkg/python/3.4.3/lib/python3.4/curses/__init__.py", line 13, in <module>
    from _curses import *
ImportError: No module named '_curses'

Various Googlez have told me that this is because when Python was compiled, the ncurses library wasn't found. 各种Googlez告诉我,这是因为在编译Python时,找不到ncurses库。

So I installed curses from ftp://ftp.gnu.org/gnu/ncurses/ (5.9) to /usr/local/pkg/ncurses/5.9 and attempted to recompile Python, passing in the location of ncurses: 所以我从ftp://ftp.gnu.org/gnu/ncurses/(5.9 )安装了curses到/usr/local/pkg/ncurses/5.9并试图重新编译Python,传递ncurses的位置:

export LDFLAGS=-L/usr/local/pkg/ncurses/5.9/lib
export CPPFLAGS="-I/usr/local/pkg/ncurses/5.9/include -I/usr/local/pkg/ncurses/5.9/include/ncurses"
./configure --enable-shared --prefix=/usr/local/pkg/python/3.4.3
make
make install

This seems like it should do it. 这似乎应该这样做。 The config.log doesn't seem to indicate any failures. config.log似乎没有表明任何失败。

checking curses.h usability... yes
checking curses.h presence... yes
checking for curses.h... yes
checking ncurses.h usability... yes
checking ncurses.h presence... yes
checking for ncurses.h... yes

I also tried using the Solaris packaging tool OpenCSW to install these packages: 我还尝试使用Solaris打包工具OpenCSW来安装这些包:

libncurses5          CSWlibncurses5       5.9,REV=2011.11.21         298.2 KB
libncurses_dev       CSWlibncurses-dev    5.9,REV=2011.11.21         258.4 KB
libncursesw5         CSWlibncursesw5      5.9,REV=2011.11.21         341.5 KB
mutt_ncurses         CSWmutt-ncurses      1.5.23,REV=2014.03.14      484.4 KB
ncurses              CSWncurses           5.9,REV=2011.11.21         123.1 KB

And then I tried: 然后我尝试了:

export LDFLAGS=-L/opt/csw/lib
export CPPFLAGS="-I/opt/csw/include -I/opt/csw/include/ncursesw"
./configure --enable-shared --prefix=/usr/local/pkg/python/3.4.3
make
make install

In either case, same situation: 无论哪种情况,同样的情况:

ImportError: No module named '_curses'

EDIT UPDATE : 编辑更新

I just realized the curses module is built during "make install" as opposed to "make", so I was missing some critical errors. 我刚刚意识到curses模块是在“make install”期间构建的,而不是“make”,所以我错过了一些关键错误。 Specifically when using the /usr/local/pkg installation of ncurses: 特别是在使用ncurses的/ usr / local / pkg安装时:

building '_curses' extension
gcc -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -I./Include -I. -IInclude -I/usr/local/pkg/ncurses/5.9/include -I/usr/local/pkg/ncurses/5.9/include/ncurses -I/usr/local/include -I/tmp/Python-3.4.3/Include -I/tmp/Python-3.4.3 -c /tmp/Python-3.4.3/Modules/_cursesmodule.c -o build/temp.solaris-2.11-i86pc.32bit-3.4/tmp/Python-3.4.3/Modules/_cursesmodule.o
gcc -shared -L/usr/local/pkg/ncurses/5.9/lib -L/usr/local/pkg/ncurses/5.9/lib -L/usr/local/pkg/ncurses/5.9/lib -I/usr/local/pkg/ncurses/5.9/include -I/usr/local/pkg/ncurses/5.9/include/ncurses build/temp.solaris-2.11-i86pc.32bit-3.4/tmp/Python-3.4.3/Modules/_cursesmodule.o -L. -L/usr/local/pkg/python/3.4.3/lib -L/usr/local/pkg/ncurses/5.9/lib -L/usr/local/lib -lncurses -lpython3.4m -o build/lib.solaris-2.11-i86pc.32bit-3.4/_curses.so
Text relocation remains                         referenced
    against symbol                  offset      in file
.rodata (section)                   0x50        /usr/local/pkg/ncurses/5.9/lib/libncurses.a(lib_color.o)
... (followed by hundreds more lines like the above)
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: ld returned 1 exit status

Failed to build these modules:
_curses               _curses_panel         readline

And specifically when using the OpenCSW installation of ncurses: 特别是在使用ncurses的OpenCSW安装时:

building '_curses' extension
gcc -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DHAVE_NCURSESW=1 -I/usr/include/ncursesw -I./Include -I. -IInclude -I/opt/csw/include -I/opt/csw/include/ncursesw -I/usr/local/include -I/tmp/Python-3.4.3/Include -I/tmp/Python-3.4.3 -c /tmp/Python-3.4.3/Modules/_cursesmodule.c -o build/temp.solaris-2.11-i86pc.32bit-3.4/tmp/Python-3.4.3/Modules/_cursesmodule.o
/tmp/Python-3.4.3/Modules/_cursesmodule.c:281:29: error: expected declaration specifiers or ‘...’ before ‘cchar_t’
/tmp/Python-3.4.3/Modules/_cursesmodule.c: In function ‘PyCurses_ConvertToCchar_t’:
/tmp/Python-3.4.3/Modules/_cursesmodule.c:299:16: error: ‘wch’ undeclared (first use in this function)
/tmp/Python-3.4.3/Modules/_cursesmodule.c:299:16: note: each undeclared identifier is reported only once for each function it appears in
/tmp/Python-3.4.3/Modules/_cursesmodule.c: In function ‘curses_window_addch_impl’:
(...and many more messages like this)

Failed to build these modules:
_curses               _curses_panel         readline

When I originally posted, I hadn't compiled ncurses with "--with-shared". 当我最初发布时,我没有使用“--with-shared”编译ncurses。 I recompiled ncurses with that option, and after which point, this worked: 我用那个选项重新编译了ncurses,之后,这个工作:

export LDFLAGS=-L/usr/local/pkg/ncurses/5.9/lib
export CPPFLAGS="-I/usr/local/pkg/ncurses/5.9/include -I/usr/local/pkg/ncurses/5.9/include/ncurses"
./configure --enable-shared --prefix=/usr/local/pkg/python/3.4.3
make
make install

¯\\_(ツ)_/¯ ¯\\ _(ツ)_ /¯

It seems you are keen on reinventing the wheel. 看来你热衷于重新发明轮子。 I recommend you to look at PKGSRC of NetBSD, which is compatible with Solaris and nowadays works quite well... even with SUN Studio compilers. 我建议你看一下NetBSD的PKGSRC ,它与Solaris兼容,现在效果很好......甚至还有SUN Studio编译器。 There are binary packages for SmartOS/Illumos that can out-of-the-box work on Solaris 11 (if you are x86). SmartOS / Illumos的二进制包可以在Solaris 11上开箱即用(如果你是x86)。

Note that this packaging stuff do have some patches + do patch Makefiles after autotools configure + injecting fake gcc , ld , as commands to PATH, which are scripts altering cmdline parameters for real compilers. 请注意,这个打包的东西确实有一些补丁+在autotools配置+注入伪gccld之后做补丁Makefile as PATH的命令,这些脚本改变了真实编译器的cmdline参数。 Do you really want to reinvent all that again? 你真的想再发一次吗?

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

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