[英]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.请注意,这会将
build
和dist
从模块的实际安装中排除。 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.