Python 'No module named' 错误;“包"不是包 [英] Python 'No module named' error; 'package' is not a package

查看:16
本文介绍了Python 'No module named' 错误;“包"不是包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行简单的导入并使用 emailage 第三方库.

I'm trying to make a simple import and use the emailage third party library.

根据他们的文档,使用他们的库的方式如下:

As per their documentation, the way to use their library is as follows:

pip install emailage-official

然后,只需导入:

from emailage.client import EmailageClient

使用 pip 安装工作正常 - 没有错误.我仔细检查了电子邮件包是否存在于正确的目录中,并且确实如此.

The install works fine with pip - no errors. I double checked to see that the emailage package exists within the proper directory, and it does.

包存在于:

C:UsersaaronAppDataLocalProgramsPythonPython37-32Libsite-packagesemailage

这个文件夹有(似乎)带有 __init__.py 和所有东西的正确文件.但是,pylint 和命令行解释器都给我一个'没有名为'emailage.client'的模块;emailage"不是包错误.

This folder has (seemingly) the correct files with an __init__.py and everything. However, both pylint and command line interpreter throw me a 'No module named 'emailage.client'; 'emailage' is not a package' error.

我的 sys.path 的输出是:

[... 
'C:\Users\aaron\AppData\Local\Programs\Python\Python37-32\lib\site-packages'
...
]

所以安装 emailage 的目录是路径的一部分......最后我 pip 安装了 numpy 只是为了测试它是否正常工作.Numpy 安装到与 emailage 相同的 site-packages 文件夹中,并且在导入时运行良好,所以我被卡住了.

So the directory where emailage is installed is a part of the path... and lastly I pip-installed numpy just to test if it worked properly. Numpy installed to the same site-packages folder as emailage, and it works fine when it is imported, so I'm stuck.

我通常不经常使用 Python,因此我们将不胜感激.

I don't typically use Python much, so any and all help would be appreciated.

推荐答案

问题出在我的文件命名.

我匆忙将文件命名为 emailage.py,然后尝试从 emailage.client 导入.

I hastily named my file emailage.py and then tried to import from emailage.client.

我假设 Python 在检查已安装的第三方库之前查看了我的当前目录并匹配了我正在处理的文件的名称.

I'm assuming that Python looked in my current directory and matched the names of the file I was working on before checking the installed third party libraries.

重命名我的文件后一切正常.

After renaming my file everything seems ok.

对于遇到类似问题的其他人 -- 注意命名冲突.有时,最简单的事情会拖累你的时间最长.

For others who run into similar problems -- beware of conflicting naming. Sometimes the simplest things trip you up the longest.

这篇关于Python 'No module named' 错误;“包"不是包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆