简体   繁体   中英

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 .

To install the module I run setup.py with the command python setup.py install in the anaconda prompt.

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

the.egg file exists and it appears as if my module has been installed.

However when i try to use the module in spyder or through the command prompt i get:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM