Import issues in Python -


I have an import error issue in the test script, it looks like doing something with the directory structure.

I have the following folder structure:

  A1F1 │ ├── __init__.py │ └ ── Src │ └── F2 │ └─ ─ __init__.py └──Test1 └──Test1 └── test_script.py  

A / F1 / SRC / F2

in F1 "__init__py" has its level at "__init__.py" at level F2

In the same level as F1, another folder "test1"

Test1 / test1 / test_script.py < / P>

In test_script.py, I have a line that says

to import F1.src.F2

with the above, telling me an error Is there any one called "F1.src.F2" Do not have the module

Does anyone know what is happening here?

imported from F1.src.F2 is a complete import To work, "F1" should be located somewhere on your Python path ( sys.path ). Normally it also includes the existing directory if you run a python on the command line.

So if the A directory is not one of the directories on your Python path and your current working directory, there is no reason that the import will work.

Module names are case sensitive. You have Src in one place and src is in another, but I'm not sure whether your real directory shows the structure or what you typed here.

If you are running test_script.py as a script, you will not be using relative import (which is how it sounds). So, be sure to do exactly what you want to do Please make sure that you run the script from A to the directory, or the entire hog, your project in a valid package with a setup.py and a test runner such as Tox .


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -