# How to do absolute import (a parent folder from the child folder)

**URL:** <https://discuss.python.org/t/how-to-do-absolute-import-a-parent-folder-from-the-child-folder/9667>\
**Category:** Python Help\
**Tags:** help\
**Created:** [July 13, 2021, 3:03am UTC](https://discuss.python.org/t/how-to-do-absolute-import-a-parent-folder-from-the-child-folder/9667 "2021-07-13T03:03:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akib62](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@akib62](https://discuss.python.org/u/akib62)\
**Post date:** [July 13, 2021, 3:03am UTC](https://discuss.python.org/t/how-to-do-absolute-import-a-parent-folder-from-the-child-folder/9667/1 "2021-07-13T03:03:21Z")

</div>

The structure of my package is given below

```auto
package_test
    main.py
    __init__.py
    folder_1
        test_1.py
        __init__.py

```

The `main.py` contains something

```auto
from folder_1.test_1 import params
if __name__ == " __main__":
    ...
    ...
    X, y = dataset
    model = LASSO(**params)
    ...

```

I want to import `X, y` to the `test_1.py` file. The `test_1.py` file contains

```auto
from package_test.main import X, y
...
...
def func():
   ...
   ...
return param

params = func()

```

I am running the program from the parent folder (from my desktop)

```auto
khali@akkas:~/Desktop$ python3 package_test/main.py --dataset=dataset1

```

But I am getting an error

```auto
ModuleNotFoundError: No module named 'package_test'

```

Could you tell me how can I solve this issue?

---

<div class="post-metadata">

**Author:** ![EpicWink](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/epicwink/32/17968_2.png) [@EpicWink](https://discuss.python.org/u/EpicWink)\
**Post date:** [July 13, 2021, 11:23pm UTC](https://discuss.python.org/t/how-to-do-absolute-import-a-parent-folder-from-the-child-folder/9667/2 "2021-07-13T23:23:36Z")

</div>

The directory of the current module `main`, which is `package_test`, would have to be included on the environment-variable `PYTHONPATH` for your import to work. This is not the best solution.

Usually, you current working directory and some library directories are in `PYTHONPATH`. Assuming your current working directory is the one containing `package_test`, you would need to change your import to:

```python
from package_test.folder_1.test_1 import params

```

Instead, if you’re happy with relative imports, you could do:

```python
from .folder_1.test_1 import params

```
