Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: with error 'is not a package'

In python 3 getting into ImportError issues. My project structure is like:

cts_sap_polaris/                                                                      |-- etc                                                                               |   |-- clean_cts_sap_polaris.yaml                                                    |   |-- clean_env_variables.tcl                                                       |   |-- cts_sap_polaris_ha_combined.yaml                                              |   |-- cts_sap_polaris.yaml                                                          |   `-- TCL_TESTBED_CONFIGS                                                           |-- __init__.py                                                                       |-- jobs |   |-- __init__.py |   |-- __pycache__ |   |   `-- run_cts_sap_polaris.cpython-34.pyc |   `-- run_cts_sap_polaris.py |-- lib |   |-- cli_check.py |   |-- cts_sap_polaris_utils.py |   |-- __init__.py |   |-- router_show_cts_cmd.py |   |-- router_show_etherchannel_cmd.py |   |-- router_show.py |   |-- utils.py |   |-- validate_show_output.py |   `-- wait_for.py |-- scripts |   |-- cts_sap_polaris_ha_combined.py |   |-- cts_sap_polaris.py |   |-- __init__.py |   `-- __pycache__ |       `-- cts_sap_polaris.cpython-34.pyc `-- test     |-- code_snippets     |-- cts_interface.json     |-- cts_interface_summary.json     |-- etherchannel_port_channel.json     |-- etherchannel_port.json     |-- __init__.py     |-- test_cts_sap_cli.py     `-- test_router_show.py 

In scripts/cts_sap_polaris.py I am trying an import

import cts_sap_polaris.lib.cli_check as cli_check 

Which is throwing this error:

ImportError: No module named 'cts_sap_polaris.lib'; 'cts_sap_polaris' is not a package. 
like image 296
agnel Avatar asked Jul 19 '16 09:07

agnel


People also ask

How do I fix the ImportError in Python?

Python's ImportError ( ModuleNotFoundError ) indicates that you tried to import a module that Python doesn't find. It can usually be eliminated by adding a file named __init__.py to the directory and then adding this directory to $PYTHONPATH .

What is ImportError in Python?

ImportError is raised when a module, or member of a module, cannot be imported. There are a two conditions where an ImportError might be raised. If a module does not exist.

How do I resolve ImportError no module name?

To get rid of this error “ImportError: No module named”, you just need to create __init__.py in the appropriate directory and everything will work fine.


1 Answers

Rename cts_sap_polaris.py to something else.

This name conflicts with the package name (which has the same name).

(credit goes to @jedwards on his comment)

like image 62
jersey bean Avatar answered Sep 20 '22 21:09

jersey bean