cc_staff
127
edits
No edit summary |
m (Rephrasing) |
||
Line 667: | Line 667: | ||
=== ModuleNotFoundError: No module named 'X' === <!--T:115--> | === ModuleNotFoundError: No module named 'X' === <!--T:115--> | ||
When | When trying to import a Python module, it may not be found. Some common causes are: | ||
* the package is not installed or not visible | * the package is not installed or is not visible to the python interpreter; | ||
* not | * the name of the module to import is not the same as the name of the package that provides it; | ||
* a broken virtual environment. | * a broken virtual environment. | ||
<!--T:116--> | <!--T:116--> | ||
To avoid such problems, do not: | |||
* | * modify the <code>PYTHONPATH</code> environment variable; | ||
* | * modify the <code>PATH</code> environment variable; | ||
* | * load a module while a virtual environment is activated (activate your virtual environment only after loading all the required modules) | ||
<!--T:117--> | <!--T:117--> | ||
When you encounter this problem, first make sure you followed the above advice. Then: | |||
* that the package is installed | * make sure that the package is installed; run <code>pip list</code>; | ||
* that | * double-check the module name (upper or lower case and underscores matter); | ||
* make sure that the module is imported at the correct level (when importing from its source directory). | |||
<!--T:118--> | <!--T:118--> | ||
In doubt, start | In doubt, start over with a new, empty virtual environment. | ||
</translate> | </translate> |