- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Cython 将 python 代码转换为共享对象时遇到问题。
安装文件在这里:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("hello.py")
)
所以在我的 Ubuntu 桌面 util 转移到 CentOS 上一切正常。
出现错误:
undefined symbol :PyUnicodeUCS4_DecodeUTF8
我用谷歌搜索,发现有很多关于此的问题,但是,几乎所有问题都说根本原因是 python 与 UCS2 或 UCS4,我理解这一点,但没有找到解决此问题的方法。
IMO,解决方法:
但是我需要重新安装所有的包
现在,我想知道是否有办法将 Cython 设置为使用指定的 UCS 模式进行编译。
非常感谢任何建议。
谢谢。
最佳答案
首先,回答您的实际问题:
I wanna if there is way to set Cython to compile with specified UCS mode.
您可以 build a separate python installation from source并将 Cython 链接到它的标题。要查找 header ,您可以使用 python-config
工具(或用于 Python 3 的 python3-config
)。它通常位于 bin
目录中,其中 python
可执行文件是:
$ # system python on my machine (macos):
$ which python-config
/usr/bin/python-config
$ # python 3 installation
$ which python3-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
$ python-config --cflags
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE
$ python-config --ldflags
-L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl -framework CoreFoundation
将输出复制到 setup.py
:
from setuptools import setup
from setuptools.extension import Extension
from Cython.Build import cythonize
cflags_ucs4 = [
'-I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m',
'-I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m',
...
]
ldflags_ucs4 = [
'-L/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin',
'-lpython3.6m',
...
]
cflags_ucs4 = [...]
ldflags_ucs2 = [...]
should_build_ucs2 = False # i.e. could be passed via sys.argv
if should_build_ucs2:
cflags = cflags_ucs2
ldflags = ldflags_ucs2
else:
cflags = cflags_ucs4
ldflags = ldflags_ucs4
extensions = [
Extension('hello.py', extra_compile_args=cflags, extra_link_args=ldflags),
]
setup(
ext_modules = cythonize(extensions)
)
但是,我不建议这样做,因为这样做不会赢得任何东西 - 您仍然需要构建和分发两个单独的包(一个用于 UCS2,另一个用于 UCS4),维护起来很麻烦。
相反,如果您正在构建一个应该可以安装在广泛的 Linux 发行版上的轮子(这很可能是您的实际目标),我建议您的构建符合 PEP 513 (manylinux1
packages)。我建议您通读它,因为当我遇到分发兼容 Linux 的轮子的问题时,它对我很有帮助。
现在,获得兼容 manylinux1
的 wheel 的一种方法是在您的机器上构建 wheel,然后运行 auditwheel
来检查特定于平台的问题并尝试解决它们:
$ pip install auditwheel
$ python setup.py bdist_wheel
$ # there should be now a mypkg-myver-cp36-cp36m-linux_x86_64.whl file in your dist directory
$ auditwheel show dist/mypkg-myver-cp36-cp36m-linux_x86_64.whl
$ # check what warnings auditwheel produced
$ # if there are warnings, try to repair them:
$ auditwheel repair dist/mypkg-myver-cp36-cp36m-linux_x86_64.whl
这应该会在 wheelhouse
目录中生成一个名为 mypkg-myver-cp36-cp36m-manylinux1_x86_64.whl
的 wheel 文件。通过运行 auditwheel show wheelhouse/mypkg-myver-cp36-cp36m-manylinux1_x86_64.whl
再次检查现在一切正常。如果 wheel 现在与 manylinux1
一致,您可以分发它并且它应该可以在大多数 Linux 发行版上运行(至少是那些带有 glibc 的发行版;像 Alpine 这样带有 musl 的发行版不会工作,如果你想支持它,你将需要构建一个单独的轮子)。
如果 auditwheel
无法修复您的轮子,您应该怎么办?最好的方法是拉一个由 PyPA 提供的特殊 docker 容器来构建 manylinux1
-compliant wheels(这是我自己使用的):
$ docker pull https://quay.io/repository/pypa/manylinux1_x86_64
在这个容器内构建的 wheel 可以在大多数 Linux 发行版上运行(不包括一些奇特的发行版,如 Alpine)。
关于python - 有什么方法可以设置用 ucs2 编译的 cython?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46968496/
我有这个 UC: this.show = function() { ... var myvar = "Text of the var." this.Property1 = m
在浏览 unicode 文档时,我有时会看到术语 UTF-16 可与 UCS-2 互换使用,也可与 UTF-32 和 UCS-4 互换使用。我想知道 UTF-8 是否也有一个很酷的昵称,比如 UCS-
我有 50% 的流量来自 UC 浏览器。在新版本的 UC 浏览器中看不到谷歌广告,那么我如何从我的网站获得良好的收入? 我过去 7 天使用过 UC Union 广告网络,但它产生了 0 美元的收入。我
ucs-4字符'🤣'的unicode值为0001f923,复制到java代码中时会自动更改为\uD83E\uDD23对应的值在 IntelliJ IDEA 中。 Java仅支持ucs-2,因此发生了
正如标题所说的那样。 $ ./configure --help | grep -i ucs --enable-unicode[=ucs[24]] 查了官方文档,发现是这样的: sys.maxuni
只要我没记错,UCS 和 BFS 是一样的,唯一的区别是它不是扩展最浅的节点,而是扩展路径成本最低的节点。 (也为此使用 PriorityQueue 而不是 Queue)所以我复制了我的 BFS 代码
我正在尝试编译/构建我的项目,但我在下面收到此错误: [dcc32 fatal error ] 不支持 F2438 UCS-4 文本编码。转换为 UCS-2 或 UTF-8 IDE 没有显示我需要转换
下面是一个简单的标记。谁能帮我写一个脚本,该脚本仅在 uc mini 浏览器中显示带有“信息框”类的 div。它应该隐藏在浏览器的其余部分。 UC Mini .info-box { d
最近几天我一直被这个问题困扰,我有一个使用 Angular 构建的单页应用程序网站。 我在网站的一个部分实现了 div 的水平滚动(旋转木马类型 View ),在其他浏览器上运行良好。 然而,在 UC
我已经安装了来自 Entrust 的 UC 多域 SSL 证书,用于两个 OpenCart 安装和一个公司域,所有这些都托管在同一 IP。 我的证书上有 3 个域,顺序如下 www.example.c
我目前正在处理的项目需要与我们不制作的客户端系统交互,因此我们无法控制数据的发送方式。问题是在 C# 中工作,它似乎对 UCS-2 没有任何支持,对 big-endian 的支持也很少。 (据我所知)
我试图在我的 42 个字符密码中随机获取小写/大写。不知何故我反而得到: ucclcjuczlclucmlc0lcdlc5lc0ucdlccucmucquc5ucslc4lckucxuctlcvlcq
我正在尝试构建此 UI,因为浏览器屏幕长时间停留在一个部分并且无法在网络上找到任何相关主题。我想实现作为对话框弹出的 UC 浏览器设置/汉堡菜单。我如何开始这件事 images link contai
这是我的代码: ` .column1{ width:calc(100% - 100px); float:left; } .column2{ width:100px; float:left; } `
我的问题是特定于浏览器的。我的 css 在移动设备上的 UC 浏览器中无法像在其他浏览器中一样正常工作。 我想将占位符垂直居中对齐。但令我惊讶的是,垂直对齐似乎有点偏离。 这是我从UC浏览器截取的截图
我有一个文本文件,它是使用某些 Microsoft 报告工具创建的。文本文件在开头包含 BOM 0xFFFE,然后是 ASCII 字符输出,字符之间有空值(即“F.i.e.l.d.1.”)。我可以使用
我想在 Go 中翻译我的 python 程序,将 unicode 字符串转换为 UCS-2 HEX 字符串。 在 python 中,这很简单: u"Bien joué".encode('utf-16-
虽然researching options用于在可能很大的SQL Server数据库中存储大多数英语但有时不是的数据,但我倾向于将大多数字符串数据存储为UTF-8编码。 但是,Microsoft之所以
我在我的项目中使用 ATMEGA128 微 Controller 和 AVR studio。我正在使用接收中断 ISR_USART0 来接收 8 个字节的数据作为数据包,并且在完成接收数据后调用该中断
我已经制作了这个脚本,但我有一个问题: $(document).ready(function() { $('html').html(function(i, v) { var searchM
我是一名优秀的程序员,十分优秀!