如何在python 3中安装setup.py中编译的脚本?
考虑以下如何在python 3中安装setup.py中编译的脚本?,python,python-3.x,compilation,setuptools,distutils,Python,Python 3.x,Compilation,Setuptools,Distutils,考虑以下setup.py文件(例如,仅在此处生成另一个源文件(false.c): 。当使用python-2*(使用pip install-e.时,此文件工作正常,同时位于包含此setup.py文件的目录中)将编译的false可执行文件安装到$VIRTUAL\u ENV/bin。但是,如果我将虚拟环境与python-3*一起使用,它将失败,并出现以下错误:() 文件“/home/zyx/.virtenvs/python3.2/lib/python3.2/site packages/distrib
setup.py
文件(例如,仅在此处生成另一个源文件(false.c
):
。当使用python-2*(使用pip install-e.
时,此文件工作正常,同时位于包含此setup.py
文件的目录中)将编译的false
可执行文件安装到$VIRTUAL\u ENV/bin
。但是,如果我将虚拟环境与python-3*一起使用,它将失败,并出现以下错误:()
文件“/home/zyx/.virtenvs/python3.2/lib/python3.2/site packages/distribute-0.6.28-py3.2.egg/setuptools/command/develop.py”,第27行,正在运行
self.install_for_development()
文件“/home/zyx/.virtenvs/python3.2/lib/python3.2/site-packages/distribute-0.6.28-py3.2.egg/setuptools/command/developer.py”,第105行,安装用于开发
self.process\u分布(无、self.dist、非self.no\u deps)
文件“/home/zyx/.virtenvs/python3.2/lib/python3.2/site packages/distribution-0.6.28-py3.2.egg/setuptools/command/easy_install.py”,第659行,正在分发中
self.install_egg_脚本(dist)
文件“/home/zyx/.virtenvs/python3.2/lib/python3.2/site packages/distribute-0.6.28-py3.2.egg/setuptools/command/developer.py”,第138行,安装脚本
script_text=f.read()
文件“/home/zyx/.virtenvs/python3.2/lib64/python3.2/codecs.py”,第300行,解码
(结果,消耗)=自身缓冲区解码(数据,自身错误,最终)
UnicodeDecodeError:“utf-8”编解码器无法解码位置208处的字节0xfc:无效的开始字节
解决方案的关键在于使用数据文件=[('bin',['false')]]
。但是这不适用于pip安装-e
,只适用于pip安装
,而不适用于-e
。如果使用纯distutils而不是setuptools,它是否有效?这可能是一个Python3转换错误,文件以文本模式打开,但应该使用二进制模式,以防它不是脚本。
#!/usr/bin/env python
from setuptools import setup
from distutils.ccompiler import new_compiler
from subprocess import check_call
with open('false.c', 'w') as F:
F.write('int main(int argc, char **argv){ return 1; }\n')
compiler = new_compiler().compiler
check_call(compiler + ['-O3', 'false.c', '-o', 'false'])
setup(
name='false',
scripts=['false'],
)
<...>
File "/home/zyx/.virtenvs/python3.2/lib/python3.2/site-packages/distribute-0.6.28-py3.2.egg/setuptools/command/develop.py", line 27, in run
self.install_for_development()
File "/home/zyx/.virtenvs/python3.2/lib/python3.2/site-packages/distribute-0.6.28-py3.2.egg/setuptools/command/develop.py", line 105, in install_for_development
self.process_distribution(None, self.dist, not self.no_deps)
File "/home/zyx/.virtenvs/python3.2/lib/python3.2/site-packages/distribute-0.6.28-py3.2.egg/setuptools/command/easy_install.py", line 659, in process_distribution
self.install_egg_scripts(dist)
File "/home/zyx/.virtenvs/python3.2/lib/python3.2/site-packages/distribute-0.6.28-py3.2.egg/setuptools/command/develop.py", line 138, in install_egg_scripts
script_text = f.read()
File "/home/zyx/.virtenvs/python3.2/lib64/python3.2/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 208: invalid start byte
<...>