# Importing a Python Module from another directory

**URL:** <https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310>\
**Category:** New to Julia\
**Tags:** pycall\
**Created:** [September 3, 2019, 1:21am UTC](https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310 "2019-09-03T01:21:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marinarrd](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@marinarrd](https://discourse.julialang.org/u/marinarrd)\
**Post date:** [September 3, 2019, 1:21am UTC](https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310/1 "2019-09-03T01:21:29Z")

</div>

I am very new to Julia. I would like to use python module from another directory. I have looked all over for instructions but none of them seem to work for me. Could someone please give me step by step instructions from using PyCall onward.

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [September 3, 2019, 2:29am UTC](https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310/2 "2019-09-03T02:29:13Z")

</div>

You’d better write an example which is not working, so people can help you achieve your goal.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 3, 2019, 12:25pm UTC](https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310/3 "2019-09-03T12:25:11Z")

</div>

> [@marinarrd](#):
>
> I would like to use python module from another directory.

You could push the directory to Python’s `sys.path` and then import the module:

```julia
using PyCall
push!(pyimport("sys")."path", "/path/of/directory")
mymodule = pyimport("mymodule")

```

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [April 16, 2020, 8:59am UTC](https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310/4 "2020-04-16T08:59:09Z")

</div>

I have put the path to by environment variable and I also can look it up in my julia session with

```julia
using PyCall
sys = pyimport("sys")
println(sys.path)

```

but I still get the following error during the import

```julia
pyimport("MyModule")

```

ERROR: PyCall.PyError("PyImport\_ImportModule\n\nThe Python package MyModule could not be found by pyimport

In addition the import of the module in Python works. What I have to do?

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [May 20, 2020, 11:13am UTC](https://discourse.julialang.org/t/importing-a-python-module-from-another-directory/28310/5 "2020-05-20T11:13:31Z")

</div>

For me the problem was solved by downgrading the Python version of 3.7 to 3.6 ([Interacting with Python - TechyTok](https://techytok.com/lesson-interacting-with-python/))
