【问题标题】:Cannot import python package installed with apt-get无法导入使用 apt-get 安装的 python 包
【发布时间】:2020-03-24 14:15:37
【问题描述】:

在 ubuntu(特别是 python:3.7.3-stretch base dockerimage)上,我运行:

$ pip install pandas
$ python -c 'import pandas'
$

而且效果很好。 然后,我尝试通过 apt-get、python3-grib 安装包 pygrib(不能使用 pip 安装)。我试试:

$ apt-get update
$ apt-get install python3-grib
$ python -c 'import pygrib'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pygrib'

(为简洁起见,省略了安装的输出)。

为什么我不能导入 pygrib?我不在虚拟环境中。

【问题讨论】:

    标签: ubuntu pip apt-get


    【解决方案1】:

    会尝试的第一件事是仔细检查您调用的python是否与您安装pygrib的python相同

    • $ which python
    • $ python -c "help("modules")"
    • $ python -c "help("modules pygrip")"

    (检查您正在调用哪个 python,以及那里安装了哪些软件包)。

    如果这不起作用,那么 ubuntu 软件包有问题 - 所以我会尝试从源代码安装;

    来自https://github.com/jswhit/pygrib

    Clone the github repository, or download a source release from https://pypi.python.org/pypi/pygrib.
    
    Copy setup.cfg.template to setup.cfg, open in text editor, follow instructions in comments for editing. If you are using the old grib_api library instead of the new eccodes library, be sure to uncomment the last line setup.cfg.
    
    Run 'python setup.py build'
    
    Run 'python setup.py install' (with sudo if necessary)
    
    Run 'python test.py' to test your pygrib installation.
    

    【讨论】:

    • 谢谢!我看到我调用了错误的 python:which python 给了我'/usr/local/bin/python',而 pygrib 的东西安装在'/usr/lib/python3'中。我该如何调和这个?
    • 你可以直接调用那个python $ /usr/lib/python3 yourscipt.py 或者直接调用$ python3 yourscript.py
    猜你喜欢
    • 2020-10-27
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多