Python“未命名模块"错误; “包裹"不是包裹 [英] Python 'No module named' error; 'package' is not a package

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

问题描述

我正在尝试进行简单的导入并使用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:\Users\aaron\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\emailage

此文件夹(貌似)带有__init__.py以及所有内容的正确文件.但是,pylint和命令行解释器都给我一个 '没有名为'emailage.client'的模块; 电子邮件"不是包裹错误.

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'
...
]

因此,安装电子邮件的目录是路径的一部分...最后,我点安装了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“未命名模块"错误; “包裹"不是包裹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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