سؤال

أحاول عرض الكثير من نص Unicode في تطبيق Curses الخاص بي. آلة التطوير الخاصة بي هي MacOSX 10.6 وأنا أستخدم Python الافتراضي الذي يتم شحنه باستخدام Apple.

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin

عندما أضفت نص Unicode إلى الشاشة ، أفسدت الشاشة جميعًا. لقد حاولت Google للحصول على حل ، وقد اقترح أشخاص آخرون ربط وحدة _curses بمكتبة libncursesw بدلاً من مكتبة libncurse.

راجعت طريقي ووجدت (انظر أدناه) في/opt/local/lib

libncurses++.a
libncurses++w.a
libncurses.5.dylib
libncurses.a
libncurses.dylib
libncursesw.5.dylib
libncursesw.a
libncursesw.dylib

كيف يمكنني التحقق من المكتبة التي ترتبط بها وحدة اللعنات الخاصة بي ، وكيف يمكنني الارتباط مع المكتبة الأخرى؟ هل من الممكن القيام بذلك دون إعادة ترجمة بيثون؟


هذا نوع من المحرجة ، لكنني أعتقد أن الحل لطباعة Unicode بشكل صحيح في بيئتي. أعتقد أنه في وقت ما قمت بتثبيت مكتبات لعنات من Macports ونسيت أن لدي بالفعل.

المشكلة التي لم يعرضها النص في المرة الأولى هي أنني بحاجة إلى ضبط اللغة داخل برنامج Python الخاص بي. اعتقدت أن الإعداد المحلي سيرث من القشرة التي أقوم بتشغيلها ، ولكن ببساطة أضفت سطرين من الكود إصلاح مشكلتي:

import locale
locale.setlocale(locale.LC_ALL,"")

رغم ذلك ، من الجيد معرفة أين تعيش مكتبة بيثون الخارجية وكيفية التحقق منها.

هل كانت مفيدة؟

المحلول

To check which other .sos a .so uses, use otool -L -- for example:

$ otool -L /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_curses.so
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_curses.so:
    /Library/Frameworks/Python.framework/Versions/2.6/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.10)

This is what I have on my Python 2.6.4 install on OSX 10.5 -- since you're using Apple's own Python on 10.6, the exact location of your _curses.so will be different, just do

$ python
>>> import _curses
>>> _curses.__file__

to see exactly where the _curses.so of interest in, then call otool -L on it.

Replacing a .so on the system-installed Python seems fraught with danger to me -- you could break something and end up having to reinstall the OS, etc. Why not install a Python download from python.org instead?

Get both the .dmg and the sources for the most recent release of 2.6 (unless you're so adventurous you want to try a release candidate 2.7;-), then you can install the .dmg (it will go to /usr/local, not overwriting the system Python; set your PATH appropriately in your .bashrc or wherever to have /usr/local/bin in your PATH ahead of /usr/bin), then, if your problem persists, you can rebuild from sources with whatever options you want, and replace the specific _curses.so in the local install, without disturbing the system directory at all (seems most prudent to me...).

نصائح أخرى

يقيم بيثون 2.6 المُحسّن من Apple مع OS X 10.6 هنا:

$ cd /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload
$ otool -L _curses*
_curses.so:
    /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)
_curses_panel.so:
    /usr/lib/libpanel.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)

ستكون فكرة سيئة للغاية لمحاولة تعديل أي شيء فيها /System/Library لأن ذلك يمكن أن يكسر OS X و/أو يتم القضاء عليه بواسطة تحديث النظام. إذا كنت بحاجة إلى إعادة التمييز ، فبناء ثعبانك الخاص من الصفر أو ابدأ به البيرة, macports, ، أو فينك.

تعديل:

يبدو أن التيار MacPorts بيثون 2.6 استخدامات التثبيت libncursesw لذلك قد يكون تثبيته أبسط الحلول:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/
$ otool -L _curses*
_curses.so:
    /opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
_curses_panel.so:
    /opt/local/lib/libpanelw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top