安装Python扩展时,Configure error: Python headers not found错误解决办法

  在配置ns3的开发环境时,需要安装Python系列的扩展包,这些扩展都是基于Python2.7.x版本的,但是Manjaro的默认Python版本是3.x,所以在安装2.7.x版本的扩展时,可能会遇到下面这样一个错误:

configure checking for python version... 3.6
configure checking for python platform... linux
configure checking for python script directory... ${prefix}/lib/python3.6/site-packages
configure checking for python extension module directory... ${exec_prefix}/lib/python3.6/site-packages
configure checking for headers required to compile python extensions...   File "<string>", line 1
configure     import sys; print sys.prefix
configure                         ^
configure SyntaxError: invalid syntax
configure   File "<string>", line 1
configure     import sys; print sys.exec_prefix
configure                         ^
configure SyntaxError: invalid syntax
configure not found
configure configure: error: Python headers not found

  我们来看一下错误原因啊,SyntaxError,语法错误,报错误的语句是

import sys; print sys.exec_prefix

  为什么会报语法错误呢?这在Python2.7.x中完全没有问题啊,可是看上面我们编译时系统默认的Python版本,是3.6,在Python3.x中,print后面是要加括号的,所以,如果我们要安装Python2.x的扩展,那么需要改一下默认的Python版本,切换到root用户,用

ls -l /usr/bin/python*

命令查看一下,通常/usr/bin/python应该只是一个符号链接指向Python3或者Python2,如果是指向Python3,那么我们需要先删除原来的符号链接,然后再新建一个指向Python2的符号链接

rm /usr/bin/python
ln -s /usr/bin/python2.7 /usr/bin/python

这就为Python2.7创建了一个符号链接,是不需要重启的,做完之后重新开始编译工作就可以了。

(base) unitree@ubuntu:~$ sudo apt-get install ffmpeg Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: apt-clone archdetect-deb bogl-bterm busybox-static cryptsetup-bin dctrl-tools dpkg-repack gir1.2-timezonemap-1.0 gir1.2-xkl-1.0 grub-common libavresample-dev libavresample4 libdc1394-22-dev libdebian-installer4 libexif-dev libgdcm-dev libgphoto2-dev libgtsam4 libilmbase-dev libmetis-dev libmetis5 libopencv4.2-java libopencv4.2-jni libopenexr-dev libraw1394-dev libtimezonemap-data libtimezonemap1 os-prober python3-icu python3-pam rdate tasksel tasksel-data Use &#39;sudo apt autoremove&#39; to remove them. The following NEW packages will be installed: ffmpeg 0 upgraded, 1 newly installed, 0 to remove and 156 not upgraded. 1 not fully installed or removed. Need to get 0 B/14.3 MB of archives. After this operation, 52.4 MB of additional disk space will be used. debconf: delaying package configuration, since apt-utils is not installed (Reading database ... 264161 files and directories currently installed.) Preparing to unpack .../ffmpeg_7%3a4.2.7-nvidia_arm64.deb ... Unpacking ffmpeg (7:4.2.7-nvidia) ... Replacing files in old package libavcodec-dev:arm64 (7:4.2.7-0ubuntu0.1) ... Replacing files in old package libavdevice-dev:arm64 (7:4.2.7-0ubuntu0.1) ... Replacing files in old package libavfilter-dev:arm64 (7:4.2.7-0ubuntu0.1) ... Replacing files in old package libavformat-dev:arm64 (7:4.2.7-0ubuntu0.1) ... Replacing files in old package libavresample-dev:arm64 (7:4.2.7-0ubuntu0.1) ... Replacing files in old package libavutil-dev:arm64 (7:4.2.7-0ubuntu0.1) ... dpkg: error processing archive /var/cache/apt/archives/ffmpeg_7%3a4.2.7-nvidia_arm64.deb (--unpack): trying to overwrite &#39;/usr/include/aarch64-linux-gnu/libpostproc/postprocess.h&#39;, which is also in package libpostproc-dev:arm64 7:4.2.7-0ubuntu0.1 怎么解决
最新发布
04-01
### 解决方案 当遇到 `dpkg` 错误提示 `/usr/include/aarch64-linux-gnu/libpostproc/postprocess.h` 被重复覆盖的问题,这通常是因为多个包试图提供相同的文件。此问题可能由冲突的依赖关系引起,尤其是在安装 `ffmpeg` 和 `libpostproc-dev` 的过程中。 以下是针对该问题的具体分析和解决方案: #### 1. **确认冲突源** 可以使用以下命令来查找哪些软件包正在尝试提供同一文件: ```bash dpkg -S /usr/include/aarch64-linux-gnu/libpostproc/postprocess.h ``` 如果存在两个或更多软件包声称拥有这个文件,则说明确实发生了冲突[^1]。 #### 2. **移除冲突包** 一旦识别到具体的冲突包名称(假设为 `package-name`),可以通过卸载其中一个包来解决问题。例如,如果发现 `libpostproc-dev` 是主要冲突者之一,可以选择将其暂删除: ```bash sudo apt-get remove --purge libpostproc-dev ``` #### 3. **重新配置 dpkg** 清理残留数据并强制完成之前未成功的操作可能会有所帮助: ```bash sudo dpkg --configure -a ``` 接着更新 APT 缓存以确保所有索引是最新的: ```bash sudo apt-get update && sudo apt-get upgrade ``` #### 4. **手动调整文件权限** 有简单的文件权限更改也能缓解此类情况。进入目录后检查是否有冗余链接或者多余的副本,并酌情处理: ```bash cd /usr/include/aarch64-linux-gnu/libpostproc/ ls -l | grep postprocess.h rm -f ./postprocess.h ``` 之后再试一次安装流程看是否恢复正常[^2]。 #### 5. **通过APT Pin优先级控制版本选择** 为了避免未来再次发生类似的冲突现象,可考虑设置特定架构下的pinning策略从而精确指定某些库应该采用哪个版本号作为默认选项。编辑偏好文档如下所示: ```plaintext Package: * Pin: origin "archive.ubuntu.com" Pin-Priority: 900 ``` #### Python脚本辅助排查工具样例 下面给出一段简单实用的小程序用于自动化检测潜在重叠区域: ```python import os def find_duplicate_headers(base_dir="/usr/include"): header_files = {} duplicates = [] for root, dirs, files in os.walk(base_dir): for file_name in files: full_path = os.path.join(root, file_name) if file_name not in header_files: header_files[file_name] = [] header_files[file_name].append(full_path) if len(header_files[file_name]) > 1 and file_name.endswith(".h"): duplicates.append(file_name) return list(set(duplicates)) if __name__ == "__main__": duplicate_headers = find_duplicate_headers() if duplicate_headers: print("Duplicate headers found:") for dh in duplicate_headers: print(f"- {dh}") else: print("No duplicate headers detected.") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值