Background: I encapsulate a package and contain multiple sub packages. Each sub package has multiple different moodles. When I refer to moodles again, it is OK to run in pychar. However, when I put this folder in Linux, there is an error: modulenotfounderror: no module named ‘package’ 。
The structure is as follows:
package:
├─ sub_package0
│ ├─ __init__.py
│ ├─ utils.py
│ └─ www.py
├─ sub_package1
│ ├─ __init__.py
│ ├─ utils1.py
│ └─ www1.py
....
├─ __init__.py
├─ abc.py
└─ xyz.py
After online Baidu, mainly tried two methods:
(1) One is to add environment variable pythonpath in. Bashrc of Linux environment http://blog.sina.com.cn/s/blog_ 9b1b494a0102vrl3.html
(2) In each moudule, add a path through the sys module https://www.cnblogs.com/dreamyu/p/7889959.html
After trying the first method, we found that the above error was still reported, while the second method was too cumbersome because it had to be added to each module. In order to save trouble, put the package directly into anaconda3’s installation path anaconda3/lib/python3.6/site-packages, and the problem is solved. The site packages library is actually the storage location of the package and module installed by PIP install.
Supplementary knowledge
Module: module. A. Py file can be called a module. Using module can avoid the conflict between function name and variable name. Functions and variables with the same name can be stored in different modules, but it should also be noted that the names of built-in functions should not conflict with each other.
Package: package. Different modules are organized by directory, similar to folder. Modules are organized by package to avoid conflicts. After the package is introduced, as long as the top-level package name does not conflict with others, all modules will not conflict with others. Please note that there is a under each package directory__ init__. Py
file, this file must exist, otherwise, python will regard this directory as a normal directory instead of a package__ init__. Py
can be an empty file or have Python code, because can be an empty file__ init__. Py
itself is a module, and its module name is its package name.
div>
Read More:
- ModuleNotFoundError: No module named ‘numpy.testing.nosetester‘
- [Solved] ModuleNotFoundError: No module named ‘win32api’
- ModuleNotFoundError: No module named ‘apt_pkg‘
- ModuleNotFoundError: No module named ‘MySQLdb‘
- ModuleNotFoundError: No module named ‘notebook‘
- ModuleNotFoundError: No module named ‘tensorboardX‘
- ModuleNotFoundError: No module named ‘ahocorasick‘ [100% Work Method]
- Modulenotfounderror: no module named ‘CV2’ – (version problem)
- Mmdet error modulenotfounderror: no module named ‘mmcv_ ext‘
- ModuleNotFoundError: No module named ‘mmcv._ext
- Jenkins reported an error modulenotfounderror: no module named filename solution
- ModuleNotFoundError: No module named ‘sklearn.datasets.samples_generator‘
- ModuleNotFoundError: No module named ‘tensorflow_core.estimator‘
- Error importing keras in jupyter Notebook: modulenotfounderror: no module named ‘keras’ solution
- Tensorflow operation report error modulenotfounderror: no module named ‘tensorflow. Python. Types’ solution
- Module not founderror: no module named ‘nets.ssd‘
- Module not found error: the solution to the problem of no module named ‘MySQL’
- Unable to call numpy in pychar, module notfounderror: no module named ‘numpy’
- How to Fix gdb error: Failed to import the site module,No module named ‘_sysconfigdata_m’
- Importerror: the perfect solution of no module named CV2!!! (not too good)