# LoadError: Couldn't find libpython PyCall

**URL:** <https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074>\
**Category:** Performance\
**Created:** [October 9, 2018, 1:28pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074 "2018-10-09T13:28:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)\
**Post date:** [October 9, 2018, 1:28pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/1 "2018-10-09T13:28:06Z")

</div>

I can’t build PyCall on linux mint 18.3

> julia\> Pkg.build(“PyCall”)  
> Building Conda ─→ `~/.julia/packages/Conda/hsaaN/deps/build.log`  
> Building PyCall → `~/.julia/packages/PyCall/rUul9/deps/build.log`  
> ┌ Error: Error building `PyCall` :  
> │ ERROR: LoadError: Couldn’t find libpython; check your PYTHON environment variable.  
> │  
> │ The python executable we tried was python3 (= version 3.5);  
> │ the library names we tried were [“libpython3.5m.so”, “libpython3.5m”, “libpython3.5”, “libpython”]  
> │ and the library paths we tried were AbstractString[“/usr/lib”, “/usr/lib”, “/usr”, “/usr/lib”]  
> │ Stacktrace:  
> │ [1] error(::String) at ./error.jl:33  
> │ [2] find\_libpython(::String) at /home/mikhail/.julia/packages/PyCall/rUul9/deps/build.jl:129  
> │ [3] top-level scope at logging.jl:313  
> │ [4] top-level scope at /home/mikhail/.julia/packages/PyCall/rUul9/deps/build.jl:196  
> │ [5] include at ./boot.jl:317 [inlined]  
> │ [6] include\_relative(::Module, ::String) at ./loading.jl:1041  
> │ [7] include(::Module, ::String) at ./sysimg.jl:29  
> │ [8] include(::String) at ./client.jl:388  
> │ [9] top-level scope at none:0  
> │ in expression starting at /home/mikhail/.julia/packages/PyCall/rUul9/deps/build.jl:170  
> └ @ Pkg.Operations /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/Operations.jl:1069

I have python3.5 at /usr/local/lib

And yes, I saw [#565](https://github.com/JuliaPy/PyCall.jl/issues/565) and [#556](https://github.com/JuliaPy/PyCall.jl/pull/556) and [PyCall: couldn't find libpython](https://discourse.julialang.org/t/pycall-couldnt-find-libpython/6116)  
They write that solved issue. But I don’t understand what to do, I’m not such cool programmer as you.

PS  
I installed everything without problems in May, what happened?

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [October 9, 2018, 1:31pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/2 "2018-10-09T13:31:34Z")

</div>

Can you verify that you have a `libpython` in one of the exact locations that the error indicates were attempted, and tell us specifically which one?

---

<div class="post-metadata">

**Author:** ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)\
**Post date:** [October 9, 2018, 1:38pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/3 "2018-10-09T13:38:21Z")

</div>

I have python3.5 at /usr/local/lib

Error says it tried:

> library paths we tried were AbstractString[“/usr/lib”, “/usr/lib”, “/usr”, “/usr/lib”]

So I noticed it, but I don’t know how to fix

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [October 9, 2018, 1:41pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/4 "2018-10-09T13:41:57Z")

</div>

Is it _libpython_ or are you talking about the python executable itself? Normally the executable should be in `/usr/bin` or `/usr/sbin` and the libraries would be in `/usr/lib`, `/usr/local/lib` or a subdirectory thereof.

Can you check which `libpython` you have in the `lib` directory?

---

<div class="post-metadata">

**Author:** ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)\
**Post date:** [October 9, 2018, 1:47pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/5 "2018-10-09T13:47:08Z")

</div>

OK, forget about it. I will just downgrade to older version of julia which worked perfectly or find something else

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [October 9, 2018, 1:48pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/6 "2018-10-09T13:48:33Z")

</div>

Ah, I think I can clear this up: I just checked on Ubuntu, `/usr/local/lib/python3.5` is where it keeps python scripts. This is not the python library which will appear as `libpython3.5.so` or something like that.

Can you check to make sure that you have `libpython3-dev` and `python3-dev` installed with  
`apt install libpython3-dev python3-dev`?

---

<div class="post-metadata">

**Author:** ![MMalakhov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmalakhov/32/10138_2.png) [@MMalakhov](https://discourse.julialang.org/u/MMalakhov)\
**Post date:** [October 9, 2018, 2:03pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/7 "2018-10-09T14:03:46Z")

</div>

> [@ExpandingMan](#):
>
> `libpython`

Many thanks.  
I installed `libpython3-dev` and it worked

---

<div class="post-metadata">

**Author:** ![msfz751](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@msfz751](https://discourse.julialang.org/u/msfz751)\
**Post date:** [August 1, 2024, 8:15pm UTC](https://discourse.julialang.org/t/loaderror-couldnt-find-libpython-pycall/16074/8 "2024-08-01T20:15:52Z")

</div>

**Unbelievable**. This solution from 2018 still applies in 2024.  
My `devcontainer.json` didn’t want to build `PyCall` but adding the python3 dev packages did the trick.

If someone interested in reproduce it, here is the code for  
`devcontainer.json`:

```julia
{
	"name": "JuliaQuartoPycall",
	"image": "mcr.microsoft.com/devcontainers/base:ubuntu",

	// Features to add to the dev container. More info: https://containers.dev/features.
	"features": {
		// A Feature to install Julia via juliaup. More info: https://github.com/JuliaLang/devcontainer-features/tree/main/src/julia.
		"ghcr.io/julialang/devcontainer-features/julia:1": {
			"channel": "release"
		},
        "ghcr.io/devcontainers/features/common-utils:2": {
            "installZsh": "true",
			"configureZshAsDefaultShell": true,
            "username": "vscode",
            "upgradePackages": "true"
        },
    "ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {
		"version": "latest",
		"installTinyTex": false,
		"installChromium": false
		},
    // A comma separated list of Linux packages
    "ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
		"packages": "libpython3-dev,python3-dev,python3-pip,qpdf"
	  }		
	},
	
	// "onCreateCommand": "pip install --no-cache-dir jupyterlab jupyterlab-git jupyterlab-lsp notebook nbclassic nbconvert",
	// "postAttachCommand": "sh ./.devcontainer/install-ijulia.sh",
	"postCreateCommand": "julia ./.devcontainer/pkgs.jl",
	
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Configure tool-specific properties.
	// "customizations": {},
    "customizations": {
        "vscode": {
            "extensions": [
                "julialang.language-julia",
                "tamasfe.even-better-toml",
				"ms-python.python",
				"ms-toolsai.jupyter"
            ]
        }
    }	
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

```

and `pkgs.jl`:

```julia
using Pkg
Pkg.add("DifferentialEquations")
Pkg.add("IJulia")
Pkg.add("ModelingToolkit")
Pkg.add(["Optimization", "OptimizationNLopt", "OptimizationPolyalgorithms"])
Pkg.add("Plots")
Pkg.add("PyCall")
Pkg.add("SciMLSensitivity")

Pkg.build("IJulia")
Pkg.build("PyCall")
Pkg.precompile()

```
