Jupyter Notebook 显示“”ModuleNotFoundError”@astropy

问题描述 投票:0回答:1

我刚刚安装了 astropy,但是当我尝试在 jupyter 实验室中运行

import astropy
时,它显示找不到模块。

我将终端中的目录更改为我的笔记本所在的目录,然后运行代码

import astropy
try:
    astropy.system_info()
except AttributeError:
    import platform; print(platform.platform())
    import sys; print("Python", sys.version)
    import astropy; print("astropy", astropy.__version__)
    import numpy; print("Numpy", numpy.__version__)
    import erfa; print("pyerfa", erfa.__version__)
    try:
        import scipy
        print("Scipy", scipy.__version__)
    except ImportError:
        print("Scipy not installed")
    try:
        import matplotlib
        print("Matplotlib", matplotlib.__version__)
    except ImportError:
        print("Matplotlib not installed")
        

显示输出:

macOS-14.6.1-arm64-arm-64bit
Python 3.11.1 (v3.11.1:a7a450f84a, Dec  6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)]
astropy 6.1.3
Numpy 2.1.1
pyerfa 2.0.1.4
Scipy not installed
Matplotlib not installed

所以,我可以假设问题不在于 pip 安装,对吗?但是,那么如何让事情顺利进行呢?

python machine-learning jupyter-lab astropy
1个回答
0
投票

您应该首先检查 astropy 是否出现在当前 python 安装的模块列表中

如果仍然不起作用,我建议使用 conda 创建自定义环境,并在那里安装所有项目依赖项,并在该项目创建的环境中启动 jupyter Notebook。

https://docs.ccv.brown.edu/oscar/connecting-to-oscar/open-ondemand/using-python-or-conda-environments-in-the-jupyter-app

© www.soinside.com 2019 - 2024. All rights reserved.