# ImportError: attempted relative import with no known parent package

**URL:** <https://forum.anaconda.com/t/importerror-attempted-relative-import-with-no-known-parent-package/20608>\
**Category:** PyScript\
**Created:** [May 4, 2022, 2:05pm UTC](https://forum.anaconda.com/t/importerror-attempted-relative-import-with-no-known-parent-package/20608 "2022-05-04T14:05:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjaan](https://avatars.discourse-cdn.com/v4/letter/a/00a5b5/32.png) [@arjaan](https://forum.anaconda.com/u/arjaan)\
**Post date:** [May 4, 2022, 2:05pm UTC](https://forum.anaconda.com/t/importerror-attempted-relative-import-with-no-known-parent-package/20608/1 "2022-05-04T14:05:58Z")

</div>

I am using Pyscript in my html files for interactive integration testing.

I figured out how to import files and additional modules, and it is working great.

However, I am not able to use relative imports in my files. Is that unsupported?

For example, I have this file structure:

```auto
index.html
|-scripts
   | - a.py
   | - b.py
   | - __init__.py

```

The file `scripts/b.py` uses a relative import:

```python
# file: b.py
from .a import my_function_a

```

In my index.html, I do this:

```nohighlight
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    <py-env>
      - paths:
        - /scripts/a.py
        - /scripts/b.py
    </py-env>
  </head>
  <body>
    <py-script> 
from a import my_function_a
from b import my_function_b
...
    </py-script>
  </body>
</html>

```

I am using a webserver to load it, and it gives this error:

```bash
Python exception:
Traceback (most recent call last):
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, in eval_code
    .run(globals, locals)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300, in run
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 8, in <module>
  File "/home/pyodide/b.py", line 12, in <module>
    from .a import my_function_a
ImportError: attempted relative import with no known parent package

```

---

<div class="post-metadata">

**Author:** ![arjaan](https://avatars.discourse-cdn.com/v4/letter/a/00a5b5/32.png) [@arjaan](https://forum.anaconda.com/u/arjaan)\
**Post date:** [May 4, 2022, 2:33pm UTC](https://forum.anaconda.com/t/importerror-attempted-relative-import-with-no-known-parent-package/20608/2 "2022-05-04T14:33:13Z")

</div>

I found that it works when I remove the relative import, and just do this:

```python
# file: scripts/b.py
from a import my_function_a

```

But now my script only works in the context of the html with pyscript, and no longer in the context of my command line.
