# Help with import

**URL:** <https://forum.djangoproject.com/t/help-with-import/8494>\
**Category:** Getting Started\
**Created:** [June 24, 2021, 2:00am UTC](https://forum.djangoproject.com/t/help-with-import/8494 "2021-06-24T02:00:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unity.buntu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/unity.buntu/32/4948_2.png) [@unity.buntu](https://forum.djangoproject.com/u/unity.buntu)\
**Post date:** [June 24, 2021, 2:00am UTC](https://forum.djangoproject.com/t/help-with-import/8494/1 "2021-06-24T02:00:58Z")

</div>

Hello `Django` Masters. Could some one help me with importing modules? I’m new in Django, so please don’t judge me too hard.

**This is my project structure:**

```auto
Main/
├── Commons
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── modules
│ │ └── network.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── Restapi
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── Main
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── __init__.py
└── manage.py

```

## 

## 

**So my issues is:**  
In `Commons` directory in views.py I need to import modules/network.py

Way where `view.py` was able to execute:  
_from modules import network_

But, than I get an error when I tried to do `python3 manage.py migrate`

```auto
    from modules import network
ModuleNotFoundError: No module named 'modules'

```

I could say, that this error maybe resolved a long long time ago, by someone, but I did not undesnartd at all, please help me with this

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 24, 2021, 2:18am UTC](https://forum.djangoproject.com/t/help-with-import/8494/2 "2021-06-24T02:18:17Z")

</div>

When you’re running a Django project, directory references are relative to the base directory, not the directory containing the code you’re currently running.

Try:  
`from Commons.modules import network`

---

<div class="post-metadata">

**Author:** ![unity.buntu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/unity.buntu/32/4948_2.png) [@unity.buntu](https://forum.djangoproject.com/u/unity.buntu)\
**Post date:** [June 24, 2021, 3:02am UTC](https://forum.djangoproject.com/t/help-with-import/8494/3 "2021-06-24T03:02:12Z")

</div>

Hello, @KenWhitesell thank you, for your replay, I’ve got an error again

```auto
> Traceback (most recent call last):
> File "Main/Commons/views.py", line 1, in <module>
> from Commons.modules import network
> ModuleNotFoundError: No module named 'Commons'
> 
> Process finished with exit code 1

```

---

<div class="post-metadata">

**Author:** ![unity.buntu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/unity.buntu/32/4948_2.png) [@unity.buntu](https://forum.djangoproject.com/u/unity.buntu)\
**Post date:** [June 24, 2021, 3:06am UTC](https://forum.djangoproject.com/t/help-with-import/8494/4 "2021-06-24T03:06:31Z")

</div>

I’ve tried `from ..Commons.modules import network` as

> [@](#):
>
> Django project, directory references are relative to the base directory, not the directory containing the code

Again an error:

```auto
Traceback (most recent call last):
  File "Main/Commons/views.py", line 1, in <module>
    from ..Commons.modules.network import endpoints
ImportError: attempted relative import with no known parent package

Process finished with exit code 1

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 24, 2021, 3:10am UTC](https://forum.djangoproject.com/t/help-with-import/8494/5 "2021-06-24T03:10:11Z")

</div>

> [@unity.buntu](#):
>
> from …Commons.modules import network

In this case, try from .modules import network

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 24, 2021, 3:13am UTC](https://forum.djangoproject.com/t/help-with-import/8494/6 "2021-06-24T03:13:23Z")

</div>

What version of Django and which version of Python are you using? You might need a \_\_init\_\_.py file in that modules directory.

---

<div class="post-metadata">

**Author:** ![unity.buntu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/unity.buntu/32/4948_2.png) [@unity.buntu](https://forum.djangoproject.com/u/unity.buntu)\
**Post date:** [June 24, 2021, 3:23am UTC](https://forum.djangoproject.com/t/help-with-import/8494/7 "2021-06-24T03:23:14Z")

</div>

I thought I don’t need the ` __init__.py` since my:  
Django version is: 3.2.4  
Python is: 3.9.4

---

<div class="post-metadata">

**Author:** ![johnmalib](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/johnmalib/32/11373_2.png) [@johnmalib](https://forum.djangoproject.com/u/johnmalib)\
**Post date:** [February 27, 2023, 6:29am UTC](https://forum.djangoproject.com/t/help-with-import/8494/8 "2023-02-27T06:29:35Z")

</div>

> [@unity.buntu](#):
>
> `ImportError: attempted relative import with no known parent package`

This error occurs when you try to import a module using a relative import, but Python cannot find the module’s parent package.

To fix this error attempted relative import with no known [parent package](http://net-informations.com/q/py/known.html), you need to make sure that the module being imported is part of a package, and that the package is on the Python path. You can do this by adding an empty **init**.py file to the package’s directory, and by making sure that the directory containing the package is on the Python path.

Alternatively, you can run the module using the -m flag with the Python interpreter, like this:

`python -m mypackage.mymodule`

This tells Python to run mymodule.py as a module, which will allow it to correctly resolve relative imports.

The main advantage of using relative imports is that they make it easier to move packages and modules around within a project, without having to update all the import statements. They also make it easier to reuse code across multiple projects, because the import paths can be modified to match the package hierarchy of each project.
