# Import package from python

**URL:** <https://discourse.julialang.org/t/import-package-from-python/47144>\
**Category:** General Usage\
**Created:** [September 23, 2020, 5:20pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144 "2020-09-23T17:20:53Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 23, 2020, 5:20pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/1 "2020-09-23T17:20:53Z")

</div>

Hi,  
I have a package installed in anaconda, and I want to use in Julia.  
I did the following:

- set python environment in Julia to be anaconda python
- and rebuilt pycall
- restart Julia  
I still have an importerror!  
Any suggession?

Thanks

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [September 23, 2020, 6:09pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/2 "2020-09-23T18:09:00Z")

</div>

Hi @nadaa and welcome to the julia discourse! Are you able to post the julia code you’re calling to import your python module and the exact error you’re getting? And are you unable to import any python modules into julia, or are you just having trouble with a particular module?

It’s hard to know what the problem might be without more information. For some general tips on getting help on discourse, check out: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 23, 2020, 8:05pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/3 "2020-09-23T20:05:38Z")

</div>

Hi @Pbellive,  
Import works with python built in packages only. For example, I tried to import pandas but got an error.

```julia
     using PyCall
    pandas = pyimport("pandas")

```

“ERROR: LoadError: PyError (PyImport\_ImportModule  
The Python package pandas could not be found by pyimport. Usually this means  
that you did not install pandas in the Python version being used by PyCall”

Thank you

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [September 23, 2020, 8:39pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/4 "2020-09-23T20:39:00Z")

</div>

You can try `pandas = pyimport_conda("pandas")`.

---

<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 23, 2020, 8:52pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/5 "2020-09-23T20:52:57Z")

</div>

Probably you didn’t configure PyCall to use the `python` installation where you installed `pandas`. Look at `PyCall.python` to see what Python installation PyCall is configured to use.

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 23, 2020, 8:57pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/6 "2020-09-23T20:57:36Z")

</div>

Thanks @tkf, I got an error  
ERROR: LoadError: MethodError: no method matching pyimport\_conda(::String)

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 23, 2020, 8:59pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/7 "2020-09-23T20:59:31Z")

</div>

Thanks. Python path in Julia is the same as Anaconda!

---

<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 23, 2020, 9:03pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/8 "2020-09-23T21:03:29Z")

</div>

Was there more output from the `pyimport` error message?

If you run the Python from `println(PyCall.python)` — that is, paste that path _exactly_ into the Terminal (don’t just run `python`) and type `import pandas`, does it work?

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 23, 2020, 9:40pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/9 "2020-09-23T21:40:31Z")

</div>

I paste the path from ` println(PyCall.python)` into the terminal (python Repl works).  
This is the whole error:

> The Python package pandas could not be found by pyimport. Usually this means  
> that you did not install pandas in the Python version being used by PyCall.
> 
> PyCall is currently configured to use the Python version at:
> 
> C:\Users\na\AppData\Local\Continuum\anaconda3\python.exe
> 
> and you should use whatever mechanism you usually use (apt-get, pip, conda,  
> etcetera) to install the Python package containing the pandas module.
> 
> One alternative is to re-configure PyCall to use a different Python  
> version on your system: set ENV[“PYTHON”] to the path/name of the python  
> executable you want to use, run Pkg.build(“PyCall”), and re-launch Julia.
> 
> Another alternative is to configure PyCall to use a Julia-specific Python  
> distribution via the Conda.jl package (which installs a private Anaconda  
> Python distribution), which has the advantage that packages can be installed  
> and kept up-to-date via Julia. As explained in the PyCall documentation,  
> set ENV[“PYTHON”]=“”, run Pkg.build(“PyCall”), and re-launch Julia. Then,  
> To install the pandas module, you can use `pyimport_conda("pandas", PKG)`,  
> where PKG is the Anaconda package the contains the module pandas,  
> or alternatively you can use the Conda package directly (via  
> `using Conda` followed by `Conda.add` etcetera).
> 
> ) \<class ‘ImportError’\>  
> ImportError(‘Unable to import required dependencies:\nnumpy: DLL load failed: Das angegebene Modul wurde nicht gefunden.’)  
> File “C:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init_\_.py”, line 17, in   
> “Unable to import required dependencies:\n” + “\n”.join(missing\_dependencies)

---

<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 23, 2020, 10:21pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/10 "2020-09-23T22:21:50Z")

</div>

> [@nadaa](#):
>
> Unable to import required dependencies:\nnumpy

This is the key line. What is the error when you try to `pyimport("numpy")`?

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 24, 2020, 9:08am UTC](https://discourse.julialang.org/t/import-package-from-python/47144/11 "2020-09-24T09:08:12Z")

</div>

> ERROR: LoadError: PyError (PyImport\_ImportModule
> 
> The Python package numpy could not be found by pyimport. Usually this means  
> that you did not install numpy in the Python version being used by PyCall.

---

<div class="post-metadata">

**Author:** ![angelv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/angelv/32/133_2.png) [@angelv](https://discourse.julialang.org/u/angelv)\
**Post date:** [September 24, 2020, 1:22pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/12 "2020-09-24T13:22:28Z")

</div>

Hi,

I had a similar issue, where I have different Python versions installed with Anaconda, and I needed to call them from within Julia. This is what I ended up with. If I remember OK, everytime I change the Python I use I have to rebuild PyCall. If you always use the same one, I guess you are ok building it only once.

```julia
ENV["PYTHON"]="/home/angelv/local/prog_langs/anaconda3/envs/chianti/bin/python"                                                                                                                                   
using Pkg
pkg"build PyCall"
using PyCall

chio = pyimport("ChiantiPy.tools.io")
ch = pyimport("ChiantiPy.core")

```

Cheers,

---

<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 24, 2020, 1:24pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/13 "2020-09-24T13:24:58Z")

</div>

> [@nadaa](#):
>
> The Python package numpy could not be found by pyimport.

Again, give the _full_ error. The low-level error reported by Python will be at the end.

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 24, 2020, 7:01pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/14 "2020-09-24T19:01:07Z")

</div>

> Building Conda ─→ `C:\Users\na\.julia\packages\Conda\3rPhK\deps\build.log`  
> Building PyCall → `C:\Users\na\.julia\packages\PyCall\zqDXB\deps\build.log`  
> ERROR: LoadError: PyError (PyImport\_ImportModule
> 
> The Python package numpy could not be found by pyimport. Usually this means  
> that you did not install numpy in the Python version being used by PyCall.
> 
> PyCall is currently configured to use the Python version at:
> 
> C:\Users\na\AppData\Local\Continuum\anaconda3\python.exe
> 
> and you should use whatever mechanism you usually use (apt-get, pip, conda,  
> etcetera) to install the Python package containing the numpy module.
> 
> One alternative is to re-configure PyCall to use a different Python  
> version on your system: set ENV[“PYTHON”] to the path/name of the python  
> executable you want to use, run Pkg.build(“PyCall”), and re-launch Julia.
> 
> Another alternative is to configure PyCall to use a Julia-specific Python  
> distribution via the Conda.jl package (which installs a private Anaconda  
> Python distribution), which has the advantage that packages can be installed  
> and kept up-to-date via Julia. As explained in the PyCall documentation,  
> set ENV[“PYTHON”]=“”, run Pkg.build(“PyCall”), and re-launch Julia. Then,  
> To install the numpy module, you can use `pyimport_conda("numpy", PKG)`,  
> where PKG is the Anaconda package the contains the module numpy,  
> or alternatively you can use the Conda package directly (via  
> `using Conda` followed by `Conda.add` etcetera).
> 
> ) \<class ‘ImportError’\>  
> ImportError(‘DLL load failed: Das angegebene Modul wurde nicht gefunden.’)  
> File “C:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init_\_.py”, line 140, in   
> from . import \_distributor\_init  
> File “C:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\_distributor\_init.py”, line 34, in   
> from . import \_mklinit

---

<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 24, 2020, 7:22pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/15 "2020-09-24T19:22:45Z")

</div>

> [@nadaa](#):
>
> ImportError(‘DLL load failed: Das angegebene Modul wurde nicht gefunden.’)  
> File “C:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\_ _init_ \_.py”, line 140, in  
> from . import \_distributor\_init  
> File “C:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\_distributor\_init.py”, line 34, in  
> from . import \_mklinit

Are you using MKL.jl, or some other MKL-enabled Julia version? In this case it’s possible that you are seeing a conflict between the MKL library loaded by Python and one in Julia?

---

<div class="post-metadata">

**Author:** ![nadaa](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Post date:** [September 25, 2020, 11:16am UTC](https://discourse.julialang.org/t/import-package-from-python/47144/16 "2020-09-25T11:16:32Z")

</div>

Hi, how can I check if MKL.jl exists?  
and how to uninstall it?

Thanks

---

<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 25, 2020, 12:23pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/17 "2020-09-25T12:23:14Z")

</div>

> [@nadaa](#):
>
> Hi, how can I check if MKL.jl exists?  
> and how to uninstall it?

If you’re not `using MKL`, then it doesn’t matter whether it is installed.

---

<div class="post-metadata">

**Author:** ![Wangwei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wangwei/32/24854_2.png) [@Wangwei](https://discourse.julialang.org/u/Wangwei)\
**Post date:** [May 7, 2021, 8:01am UTC](https://discourse.julialang.org/t/import-package-from-python/47144/18 "2021-05-07T08:01:59Z")

</div>

Hello, not sure if you have figured it out. I had a similar problem, this works for me. Uninstall Julia and reinstall it to the same folder where Anaconda is. Hope this helps!

---

<div class="post-metadata">

**Author:** ![Katja](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@Katja](https://discourse.julialang.org/u/Katja)\
**Post date:** [June 28, 2021, 1:34pm UTC](https://discourse.julialang.org/t/import-package-from-python/47144/19 "2021-06-28T13:34:31Z")

</div>

It worked for me too!
