【问题标题】:Unable to import Utils and Generators package无法导入 Utils 和 Generators 包
【发布时间】:2021-07-10 13:19:24
【问题描述】:

我已经提到了这些帖子12345

但我仍然无法解决此问题。可能是因为其他问题太技术性了。

我做了以下

a) 我启动了 jupyter notebook(将文件保存在桌面)

b) 导入常规包,如 Pandas、Numpy、Scipy 等。

c) 后来我尝试导入 UtilsGenerators 包,但它抛出了错误。

pip install Utils  #success
pip install Generators #success
pip list-v #returned the below location

utils 1.0.1     c:\users\test\appdata\local\continuum\anaconda3\lib\site-packages pip
generators 2020.4.27 c:\users\test\appdata\local\continuum\anaconda3\lib\site-packages pip

When I tried importing `Utils` and `Generators` package, I get the same error as well

import psycopg2
import pandas as pd
import numpy as np
import Utils
import Generators

ModuleNotFoundError: No module named 'Utils'
ModuleNotFoundError: No module named 'Generators'

导入Utils 包是否需要任何其他文件?

为什么人们经常谈论成功导入utils的项目目录?我只是想像Pandas 一样导入它;不关心项目目录。我刚刚启动了一个 jupyter notebook 并尝试安装 Utils

如何成功导入这些包?这些包不能像pandas这样的常规包一样导入吗?因为这些包我都是全新安装的,而且都导入成功了

我还通过输入import python_utils 尝试了此post 中的建议,但没有帮助

任何关于如何解决这个问题的教程或步骤对我来说真的很有帮助。

【问题讨论】:

    标签: python python-3.x module pip importerror


    【解决方案1】:

    import 语句区分大小写,而pip不区分大小写

    根据PEP-0426,它描述了一种发布和交换与 Python 发行版/包相关的元数据的机制,

    所有分布名称的比较必须不区分大小写,并且 必须认为连字符和下划线是等价的。

    所以从技术上讲,pip install Utilspip install UTILSpip install utils 都将安装名为 utils 的相同发行版/包。

    要解决问题,您必须更改您的代码

    import Utils
    import Generators
    

    import utils
    import generators
    

    【讨论】:

    • @TheGreat Sure :)
    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 2019-08-06
    • 1970-01-01
    • 2014-05-29
    • 2022-12-21
    • 1970-01-01
    相关资源
    最近更新 更多