简体   繁体   English

ModuleNotFoundError:没有名为“my_module”的模块

[英]ModuleNotFoundError: No module named 'my_module'

I have a custom module have written and i am having trouble installing.我已经编写了一个自定义模块,但我无法安装。 Here is the structure of the module.这是模块的结构。

├── my_module
│   ├── .git
│   │   ├── <..>
│   ├── build
│   │   ├── <..>
│   ├── class_a
│   │   ├── __init__.py
│   │   ├── class_a_name.py
│   ├── class_b
│   │   ├── __init__.py
│   │   ├── class_b_name.py
│   ├── dist
│   │   ├── <..>
│   ├── my_module.egg.info
│   │   ├── <..>
│   ├── setup.py
│       ├── .gitignore

This is stored within C:\Users\my_name\repos\my_module .这存储在C:\Users\my_name\repos\my_module中。

To install the module I run setup.py with the command python setup.py install in the anaconda prompt.要安装模块,我在 anaconda 提示符下使用命令python setup.py install运行setup.py

When this is run if i navigate to C:\Users\my_name\AppData\Local\Continuum\anaconda3\Lib\site-packages\my_module-0.2-py3.7.egg如果我导航到C:\Users\my_name\AppData\Local\Continuum\anaconda3\Lib\site-packages\my_module-0.2-py3.7.egg

the.egg file exists and it appears as if my module has been installed. .egg 文件存在,看起来好像我的模块已安装。

However when i try to use the module in spyder or through the command prompt i get:但是,当我尝试在 spyder 中或通过命令提示符使用该模块时,我得到:

ModuleNotFoundError: No module named 'my_module'

I don't think this is a path issue like a lot of the other questions on the topic.我不认为这是一个路径问题,就像该主题的许多其他问题一样。

Thanks in advance, happy to elaborate.提前感谢,很高兴详细说明。

It's a path issue.是路径问题。 (and yes, setting up the paths proper is really annoying) (是的,正确设置路径真的很烦人)

Proper path for imports would look like:导入的正确路径如下所示:

├── my_module
│   ├── .git
│   │   ├── <..>
│   ├── build
│   │   ├── <..>
│   │   my_module         <-- NEW
│   │   ├── __init__.py   <-- NEW
│   │   ├── class_a
│   │   │   ├── __init__.py
│   │   │   ├── class_a_name.py
│   │   ├── class_b
│   │   │   ├── __init__.py
│   │   │   ├── class_b_name.py
│   ├── dist
│   │   ├── <..>
│   ├── my_module.egg.info
│   │   ├── <..>
│   ├── setup.py

Note that this would exclude build and dist from the actual installation of your module.请注意,这会将builddist从模块的实际安装中排除。 Move them up to if you don't want that.如果你不想要的话,把它们移到上面。

This can perhaps be accomplished by moving setup.py outwards instead of creating a new folder, but that's up to you.这也许可以通过向外移动 setup.py 而不是创建新文件夹来完成,但这取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 出现错误 ModuleNotFoundError: No module named 'my_module' - Getting error ModuleNotFoundError: No module named 'my_module' `pickle`:另一个`ImportError:没有名为my_module的模块。 - `pickle`: yet another `ImportError: No module named my_module` (又一个)“导入错误:没有名为 my_module 的模块” - (Yet Another) 'ImportError: No module named my_module' Python - 在终端中“没有名为 my_module 的模块”,但在 PyCharm 中没有 - Python - “No module named my_module” in terminal, but not in PyCharm 如何导入自己的模块进行模拟? (导入错误:没有名为my_module的模块!) - How to import own module for mocking? (import error: no module named my_module!) 如何解释“ import my_module”和“ from my_module import my_str”之间的区别? - How to explain difference between “import my_module” and “from my_module import my_str”? ModuleNotFoundError:没有名为“my_pkg”的模块 - ModuleNotFoundError: No module named 'my_pkg' ModuleNotFoundError: 没有名为“my_app”的模块 - ModuleNotFoundError: No module named 'my_app' “ModuleNotFoundError:没有命名模块<package> “在我的 Docker 容器中 - "ModuleNotFoundError: No module named <package>" in my Docker container 我的代码中的错误 ModuleNotFoundError: No module named 'emnist' - Error in my code ModuleNotFoundError: No module named 'emnist'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM