安装维护的pygtftk包时出现clang/gcc文件未找到错误求助
pygtftk安装时clang/gcc找不到exclude.cpp的解决思路
问题背景
维护pygtftk包以适配Python 3.10/3.11时,在Unix(Python 3.9.15)和OSX系统执行以下命令安装:
git clone git@github.com:dputhier/pygtftk.git cd pygtftk python setup.py install --user
工具报错找不到exclude.cpp,但该文件实际路径为./pygtftk/stats/intersect/read_bed/exclude.cpp,且setup.py的Extension配置中已指定正确相对路径:
cython_ologram_3 = Extension(name='pygtftk.stats.intersect.read_bed.read_bed_as_list', sources=["pygtftk/stats/intersect/read_bed/read_bed_as_list.pyx", "pygtftk/stats/intersect/read_bed/exclude.cpp"], # Include custom Cpp code extra_compile_args=extra_comp_cython, extra_link_args=extra_link_cython, include_dirs=[np.get_include()], language='c++')
解决思路
确认setup.py执行的工作目录
在setup.py开头添加调试代码,打印当前工作目录,验证是否在项目根目录:import os print("Current working directory:", os.getcwd())如果输出不是项目根目录,需确保安装命令从根目录执行,或者将源文件路径改为基于setup.py所在位置的绝对路径。
改用绝对路径指定源文件
基于setup.py的位置生成绝对路径,避免工作目录变化导致的路径失效:from pathlib import Path setup_dir = Path(__file__).parent cython_ologram_3 = Extension( name='pygtftk.stats.intersect.read_bed.read_bed_as_list', sources=[ str(setup_dir / "pygtftk/stats/intersect/read_bed/read_bed_as_list.pyx"), str(setup_dir / "pygtftk/stats/intersect/read_bed/exclude.cpp") ], extra_compile_args=extra_comp_cython, extra_link_args=extra_link_cython, include_dirs=[np.get_include()], language='c++' )注:Path对象需转为字符串,避免setuptools解析异常。
清理构建缓存后重新安装
旧的构建缓存可能残留错误路径,清理后再尝试安装:rm -rf build/ dist/ pygtftk.egg-info/ find . -name "*.so" -o -name "*.cpp" -o -name "*.c" | grep -v exclude.cpp | xargs rm -f python setup.py install --user手动预编译Cython文件
先将.pyx文件转为C++文件,再执行安装,避免编译流程中路径解析出错:cython pygtftk/stats/intersect/read_bed/read_bed_as_list.pyx --cplus python setup.py install --user给编译器添加源文件目录
在编译参数中指定exclude.cpp所在目录,让编译器能找到该文件:extra_comp_cython += ["-Ipygtftk/stats/intersect/read_bed/"]
内容的提问来源于stack exchange,提问作者dputhier
相关产品推荐
相关产品推荐

