# Where to put the module?

**URL:** <https://discuss.python.org/t/where-to-put-the-module/43377>\
**Category:** Python Help\
**Tags:** help\
**Created:** [January 17, 2024, 2:05am UTC](https://discuss.python.org/t/where-to-put-the-module/43377 "2024-01-17T02:05:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wdlang06](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/wdlang06/32/16566_2.png) [@wdlang06](https://discuss.python.org/u/wdlang06)\
**Post date:** [January 17, 2024, 2:05am UTC](https://discuss.python.org/t/where-to-put-the-module/43377/1 "2024-01-17T02:05:30Z")

</div>

I downloaded a package from Github. In some directory A, there is a jupyter file which starts with

```auto
from some_module import some_function 

```

I find that the file ‘some\_module.py’ is not in directory A, but in a sibling directory of A.

How did vscode or jupyter know where to look for the module ‘some\_module’?

I did not do anything but downloading and unzipping.

ps. I am sorry if this question is very trivial

---

<div class="post-metadata">

**Author:** ![onePythonUser](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/onepythonuser/32/19158_2.png) [@onePythonUser](https://discuss.python.org/u/onePythonUser)\
**Post date:** [January 17, 2024, 4:45am UTC](https://discuss.python.org/t/where-to-put-the-module/43377/2 "2024-01-17T04:45:39Z")

</div>

Hi,

based on your description, you have the following directory set-up (or approximate):

![sample_package](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/0/5/053f66226323da0aac08e007225d0d9a556d12ea.png)

One of the ways that Python uses for importing files is by setting up the system **PATH**. The system **PATH** includes directories that tells Python where to look when importing modules. It scans them from left-to-right.

If you type the following in your editor, you too can find your system **PATH** s for a particular module or package:

```auto
import sys
sys.path

```

You can modify your system **PATH** s at anytime. So, somewhere in the program that you downloaded, the system **PATH** has been defined.

**Example:**  
For simplicity, let’s assume you have a package with two directories as highlighted by the figure above. **directory\_A** has `a.py` module and **sibling\_directory** has `b.y` module.

Let’s assume `a.py` has the following code:

```auto
''' a.py # C:\Users\mycomp\Desktop\test_pkg\directory_A\a.py '''

import sys
sys.path.append(r'C:\Users\mycomp\Desktop\test_pkg\sibling_directory')

from b import multi

multi(5, 4)

```

`b.py` has the following code:

```auto
''' b.py # C:\Users\mycomp\Desktop\test_pkg\sibling_directory\b.py '''

def multi(x, y):
    print('x * y is: ', x *y)

```

Notice that `a.py` has explicitly told the module where to look for modules when importing (the first two lines of code). If I did not include them, the import would fail. You can try this yourself on your computer. Just make sure the **PATH** matches your system. Comment out the first two lines and then uncomment them and run again and make observations. Although I have explicitly added this particular **PATH** in the same module (`a.py`), somewhere in the package that you downloaded these instructions were added, telling Python (your program) in which directories to look for when importing modules. Note that this is not the only way of setting imports up for your program packages, however.

I hope this helps you with furthering your understanding.

\*\*\*\* UPDATE \*\*\*\*

Here is a nice little trick so that you can use to view the **PATH** directories a little better:

Type the following to assign a name to the PATH directory list for reference in a **for loop** :

```auto
import sys
path_directories = sys.path 

```

Next, iterate through the list so that they are printed sequentially:

```auto
num = 1
for path in path_directories:
    print('{}. {}'.format(num, path))
    num += 1

```

Note that the first item in the list may be an empty value ( ’ '), so delete it from the list so that only valid directories are displayed.

---

<div class="post-metadata">

**Author:** ![jeff5](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jeff5/32/1518_2.png) [@jeff5](https://discuss.python.org/u/jeff5)\
**Post date:** [January 17, 2024, 7:49am UTC](https://discuss.python.org/t/where-to-put-the-module/43377/3 "2024-01-17T07:49:55Z")

</div>

> [@wdlang06](#):
>
> How did vscode or jupyter know where to look for the module ‘some\_module’?

The mainstream way to install packages these days is with `pip`, and they go into `site-packages`, in the library of your your Python interpreter, which is on the standard search path for modules `sys.path` that @onePythonUser refers to. You can do this from within a Jupyter notebook. [Easy install python modules for Jupyter notebooks? - Stack Overflow](https://stackoverflow.com/questions/64487631/easy-install-python-modules-for-jupyter-notebooks). There are several alternative commands. I think both answers given here are right, but it depends on your set-up.

`pip` only works if the project has packaged and published its work on PyPI. (Not quite true: it will install from a package file if you know how.) If you have to download Python packages without that kind of automation, you can put them in `site-packages` yourself and it should work.

In many cases, you want a `site-packages` that is private to each project, so you have control over what packages are available where. This is something `venv` does for you. [venv — Creation of virtual environments — Python 3.12.1 documentation](https://docs.python.org/3/library/venv.html) . It is well worth learning about.

VSCode or Jupyter _may_ be creating one of these virtual environments behind the scenes. I don’t know enough to say they will/won’t have. If installing packages by hand, I would first ask inside my project where its `site-packages` was placed.
