Ubuntu的apt-file解决依赖问题

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. 背景

平常我们在安装应用时,经常会碰到缺少各种文件、依赖等问题,例如缺少.so文件。Ubuntu中提供了一个强大的工具apt-file来查找依赖。最适合的场景是在Docker中使用,因为Docker Image的系统通常是Ubuntu。

2. 安装

apt-file的安装命令如下:

1
2
3
4
5
6
# Install
$ apt-get update
$ apt-get install apt-file

# Update apt-file
$ apt-file update

3. 搜索缺少的文件

如果缺少cv.py文件,则搜索cv.py文件,apt-file会列出包含cv.py的包,发现需要的包是python-opencv,然后安装ython-opencv

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 命令格式
$ apt-file seach [filename]

# Demo
$ apt-file search cv.py
gnuradio: /usr/lib/python2.7/dist-packages/gnuradio/analog/wfm_rcv.py
gnuradio: /usr/share/gnuradio/examples/uhd/usrp_am_mw_rcv.py
gnuradio: /usr/share/gnuradio/examples/uhd/usrp_nbfm_rcv.py
gnuradio: /usr/share/gnuradio/examples/uhd/usrp_tv_rcv.py
gnuradio: /usr/share/gnuradio/examples/uhd/usrp_wfm_rcv.py
gnuradio: /usr/share/gnuradio/examples/uhd/usrp_wxapt_rcv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/db_recv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/direct_recv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/messenger/recv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/reactor/recv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/selected_recv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/simple_recv.py
libqpid-proton2-dev-examples: /usr/share/proton-0.10/examples/python/tx_recv.py
lowpan-test-tools: /usr/lib/x86_64-linux-gnu/lowpan-tools/test_recv.py
python-kivy: /usr/lib/python2.7/dist-packages/kivy/core/camera/camera_opencv.py
python-mvpa2-doc: /usr/share/doc/python-mvpa2-doc/examples/nested_cv.py
python-opencv: /usr/lib/python2.7/dist-packages/cv.py
python-pyavm: /usr/lib/python2.7/dist-packages/pyavm/cv.py
python-pysnmp4: /usr/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/ntfrcv.py
python-pysnmp4: /usr/share/pyshared/pysnmp/entity/rfc3413/ntfrcv.py
python-pysnmp4-doc: /usr/share/doc/python-pysnmp4-doc/examples/v1arch/manager/ntfrcv.py
python-scapy: /usr/lib/python2.7/dist-packages/scapy/sendrecv.py
python-scapy: /usr/share/pyshared/scapy/sendrecv.py
python3-kivy: /usr/lib/python3/dist-packages/kivy/core/camera/camera_opencv.py
python3-pyavm: /usr/lib/python3/dist-packages/pyavm/cv.py
python3-pysnmp4: /usr/lib/python3/dist-packages/pysnmp/entity/rfc3413/ntfrcv.py

4. 列出包中的文件

查看python-opencv中的文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 命令格式
$ apt-file list [package name]

# Demo
$ apt-file list python-opencv
python-opencv: /usr/lib/python2.7/dist-packages/cv.py
python-opencv: /usr/lib/python2.7/dist-packages/cv2.x86_64-linux-gnu.so
python-opencv: /usr/share/doc/python-opencv/changelog.Debian.gz
python-opencv: /usr/share/doc/python-opencv/copyright
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/__init__.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/CamShiftConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/ContourMomentsConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/ConvexHullConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/EdgeDetectionConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/FBackFlowConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/FaceDetectionConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/FindContoursConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/GeneralContoursConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/GoodfeatureTrackConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/HoughCirclesConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/HoughLinesConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/LKFlowConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/PeopleDetectConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/PhaseCorrConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/SegmentObjectsConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/SimpleFlowConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/WatershedSegmentationConfig.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/cfg/__init__.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Circle.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_CircleArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_CircleArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Contour.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_ContourArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_ContourArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Face.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_FaceArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_FaceArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Flow.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_FlowArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_FlowArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_FlowStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Line.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_LineArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_LineArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Moment.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_MomentArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_MomentArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Point2D.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Point2DArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Point2DArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Point2DStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Rect.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_RectArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_RectArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_RotatedRect.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_RotatedRectArray.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_RotatedRectArrayStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_RotatedRectStamped.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/_Size.py
python-opencv-apps: /usr/lib/python2.7/dist-packages/opencv_apps/msg/__init__.py
python-opencv-apps: /usr/share/doc/python-opencv-apps/changelog.Debian.gz
python-opencv-apps: /usr/share/doc/python-opencv-apps/copyright

5. 其它系统

在其它系统中,例如CentOS中,可以用yum whatprovides命令来查询命令所在的包。

如果有收获,可以请我喝杯咖啡!