问题导入 subprocess32
Issue importing subprocess32
我正在尝试通过 buildroot 使用我的 python 2.7 安装来安装 subprocess32。它似乎安装正确,但是当我将它导入嵌入式系统时出现错误:
>>> import subprocess32
/usr/lib/python2.7/site-packages/subprocess32.py:472: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your pro
gram uses threads.
"program uses threads.", RuntimeWarning)
按照这条路径,我尝试导入 _posixsubprocess
import _posixsubprocess
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (init_posixsubprocess)
subprocess32 似乎有自己的版本,但在这种情况下不起作用?
这是我的 make 文件:
#############################################################
#
# Subprocess32 module for python
#
#############################################################
SUBPROCESS32_VERSION = 3.2.7
SUBPROCESS32_SOURCE = subprocess32-$(SUBPROCESS32_VERSION).tar.gz
SUBPROCESS32_SITE = https://pypi.python.org/pypi/subprocess32
SUBPROCESS32_DEPENDENCIES = python
define SUBPROCESS32_BUILD_CMDS
(cd $(@D); $(HOST_DIR)/usr/bin/python setup.py build)
endef
define SUBPROCESS32_INSTALL_TARGET_CMDS
(cd $(@D); $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr)
endef
$(eval $(call GENTARGETS,package,subprocess32))
有一个类似的post关于这个Python Error The _posixsubprocess module is not being used但是答案是评论中的link已经死了。对我的问题有什么想法吗?
setup.py:
#!/usr/bin/python
import os
import sys
from distutils.core import setup, Extension
def main():
if sys.version_info[0] != 2:
sys.stderr.write('This backport is for Python 2.x only.\n')
sys.exit(1)
ext = Extension('_posixsubprocess', ['_posixsubprocess.c'],
depends=['_posixsubprocess_helpers.c'])
if os.name == 'posix':
ext_modules = [ext]
else:
ext_modules = []
setup(
name='subprocess32',
version='3.2.7',
description='A backport of the subprocess module from Python 3.2/3.3 for use on 2.x.',
long_description="""
This is a backport of the subprocess standard library module from
Python 3.2 & 3.3 for use on Python 2.
It includes bugfixes and some new features. On POSIX systems it is
guaranteed to be reliable when used in threaded applications.
It includes timeout support from Python 3.3 but otherwise matches
3.2's API. It has not been tested on Windows.""",
license='PSF license',
maintainer='Gregory P. Smith',
maintainer_email='greg@krypto.org',
url='https://github.com/google/python-subprocess32',
ext_modules=ext_modules,
py_modules=['subprocess32'],
classifiers=[
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: Python Software Foundation License',
'Operating System :: POSIX',
'Operating System :: POSIX :: BSD',
'Operating System :: POSIX :: Linux',
'Operating System :: POSIX :: SunOS/Solaris',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Programming Language :: Python :: Implementation :: CPython',
],
)
if __name__ == '__main__':
main()
我不确定您使用的是哪个 Buildroot 版本,但如果它仍然是使用 GENTARGETS
宏并且没有 python-package
基础结构的版本,那么它必须是一个非常非常非常旧的版本。请先升级,因为近年来在 Python 支持中进行了很多很多修复。
问题是 distutils
使用了错误的编译器来构建共享对象(其他对象使用了正确的编译器)。在构建阶段设置以下 LDSHARED
变量解决了问题:
LDSHARED="$(TARGET_CC) -pthread -shared"
我正在尝试通过 buildroot 使用我的 python 2.7 安装来安装 subprocess32。它似乎安装正确,但是当我将它导入嵌入式系统时出现错误:
>>> import subprocess32
/usr/lib/python2.7/site-packages/subprocess32.py:472: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your pro
gram uses threads.
"program uses threads.", RuntimeWarning)
按照这条路径,我尝试导入 _posixsubprocess
import _posixsubprocess
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (init_posixsubprocess)
subprocess32 似乎有自己的版本,但在这种情况下不起作用?
这是我的 make 文件:
#############################################################
#
# Subprocess32 module for python
#
#############################################################
SUBPROCESS32_VERSION = 3.2.7
SUBPROCESS32_SOURCE = subprocess32-$(SUBPROCESS32_VERSION).tar.gz
SUBPROCESS32_SITE = https://pypi.python.org/pypi/subprocess32
SUBPROCESS32_DEPENDENCIES = python
define SUBPROCESS32_BUILD_CMDS
(cd $(@D); $(HOST_DIR)/usr/bin/python setup.py build)
endef
define SUBPROCESS32_INSTALL_TARGET_CMDS
(cd $(@D); $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr)
endef
$(eval $(call GENTARGETS,package,subprocess32))
有一个类似的post关于这个Python Error The _posixsubprocess module is not being used但是答案是评论中的link已经死了。对我的问题有什么想法吗?
setup.py:
#!/usr/bin/python
import os
import sys
from distutils.core import setup, Extension
def main():
if sys.version_info[0] != 2:
sys.stderr.write('This backport is for Python 2.x only.\n')
sys.exit(1)
ext = Extension('_posixsubprocess', ['_posixsubprocess.c'],
depends=['_posixsubprocess_helpers.c'])
if os.name == 'posix':
ext_modules = [ext]
else:
ext_modules = []
setup(
name='subprocess32',
version='3.2.7',
description='A backport of the subprocess module from Python 3.2/3.3 for use on 2.x.',
long_description="""
This is a backport of the subprocess standard library module from
Python 3.2 & 3.3 for use on Python 2.
It includes bugfixes and some new features. On POSIX systems it is
guaranteed to be reliable when used in threaded applications.
It includes timeout support from Python 3.3 but otherwise matches
3.2's API. It has not been tested on Windows.""",
license='PSF license',
maintainer='Gregory P. Smith',
maintainer_email='greg@krypto.org',
url='https://github.com/google/python-subprocess32',
ext_modules=ext_modules,
py_modules=['subprocess32'],
classifiers=[
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: Python Software Foundation License',
'Operating System :: POSIX',
'Operating System :: POSIX :: BSD',
'Operating System :: POSIX :: Linux',
'Operating System :: POSIX :: SunOS/Solaris',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Programming Language :: Python :: Implementation :: CPython',
],
)
if __name__ == '__main__':
main()
我不确定您使用的是哪个 Buildroot 版本,但如果它仍然是使用 GENTARGETS
宏并且没有 python-package
基础结构的版本,那么它必须是一个非常非常非常旧的版本。请先升级,因为近年来在 Python 支持中进行了很多很多修复。
问题是 distutils
使用了错误的编译器来构建共享对象(其他对象使用了正确的编译器)。在构建阶段设置以下 LDSHARED
变量解决了问题:
LDSHARED="$(TARGET_CC) -pthread -shared"