# Build PyCall error

**URL:** <https://discourse.julialang.org/t/build-pycall-error/59252>\
**Category:** New to Julia\
**Created:** [April 14, 2021, 3:17am UTC](https://discourse.julialang.org/t/build-pycall-error/59252 "2021-04-14T03:17:12Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 14, 2021, 3:17am UTC](https://discourse.julialang.org/t/build-pycall-error/59252/1 "2021-04-14T03:17:12Z")

</div>

Hello everyone, it’s been a while since I had any errors while installing Julia. When Julia tries to install PyCall, it runs the script

.julia/packages/PyCall/tqyST/deps/find\_libpython.py

is generates many error messages, of which I think the most important is

File “/home/marllos/.julia/packages/PyCall/BD546/deps/find\_libpython.py”, line 33, in   
import ctypes.util

When I time give the command “import ctypes.util” directly in pytyon 3.9.4, I get the message:

ModuleNotFoundError: No module named ‘\_ctypes’

I appreciate any help.

julia\> versioninfo()  
Julia Version 1.6.0  
Commit f9720dc2eb (2021-03-24 12:55 UTC)  
Platform Info:  
OS: Linux (x86\_64-pc-linux-gnu)  
CPU: AMD EPYC 7452 32-Core Processor  
WORD\_SIZE: 64  
LIBM: libopenlibm  
LLVM: libLLVM-11.0.1 (ORCJIT, znver2)

shell\> lsb\_release -a  
No LSB modules are available.  
Distributor ID: Ubuntu  
Description: Ubuntu 20.04.2 LTS  
Release Date: 20.04  
Codename: focal

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 14, 2021, 11:47pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/2 "2021-04-14T23:47:45Z")

</div>

Can anyone tell me something?

---

<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:** [April 15, 2021, 12:42am UTC](https://discourse.julialang.org/t/build-pycall-error/59252/3 "2021-04-15T00:42:24Z")

</div>

> [@marllos](#):
>
> When I time give the command “import ctypes.util” directly in pytyon 3.9.4, I get the message:
> 
> ModuleNotFoundError: No module named ‘\_ctypes’

If you type `import ctypes.util` directly in Python and get an error, then your Python installation is broken.

Fix/reinstall your python installation (or let PyCall install its own by setting `ENV["PYTHON"]=""` before building PyCall).

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 15, 2021, 1:08am UTC](https://discourse.julialang.org/t/build-pycall-error/59252/4 "2021-04-15T01:08:19Z")

</div>

The Python installed is the one that came with the default Ubuntu installation. What I could do was apt-get remove python3 and then apt-get install python3, but the error still persisted.

---

<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:** [April 15, 2021, 2:33am UTC](https://discourse.julialang.org/t/build-pycall-error/59252/5 "2021-04-15T02:33:19Z")

</div>

Maybe you have some environment variable, like `PYTHONPATH`, set to a bogus value that is confusing Python.

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 15, 2021, 6:16pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/6 "2021-04-15T18:16:50Z")

</div>

I checked, it doesn’t. The OS was installed 3 days ago. The server had not yet been used when I installed Julia.The ENV tip worked, but I still want the default solution, using the Python that comes with Ubuntu, just like the 20 times I installed Julia without errors.

---

<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:** [April 15, 2021, 6:19pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/7 "2021-04-15T18:19:43Z")

</div>

> [@marllos](#):
>
> I still want the default solution, using the Python that comes with Ubuntu, just like the 20 times I installed Julia without errors.

Then complain to the OS vendor or your local sysadmin. If `import ctypes.util` fails when you type it manually _in Python_, then it is a problem with your Python setup — it has nothing to do with Julia or PyCall.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 15, 2021, 6:24pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/8 "2021-04-15T18:24:43Z")

</div>

See this perhaps:  
[https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul/41310760#41310760](https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul/41310760#41310760)

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 15, 2021, 6:58pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/9 "2021-04-15T18:58:08Z")

</div>

I also think that the problem has nothing to do with Julia or PyCall.

My procedure has always been:

1. ubuntu installation
2. sudo apt-get install python3-matplotlib libqt5widgets5
3. installation of Julia
4. sudo ln -s /opt/julia-1.6.0/bin/julia /usr/local/bin/julia

I did this on Ubuntu 20.04.2 and Ubuntu 21.04 and everything went fine. When I did it again on the latest Ubuntu 20.04.2 it gave a lot of errors:

(@v1.6) pkg\> add PyCall  
Installing known registries into `~/.julia`  
Added registry `General` to `~/.julia/registries/General`  
Resolving package versions…  
Installed MacroTools ───── v0.5.6  
Installed VersionParsing ─ v1.2.0  
Installed Conda ────────── v1.5.1  
Installed JSON ─────────── v0.21.1  
Installed Parsers ──────── v1.1.0  
Installed PyCall ───────── v1.92.3  
Updating `~/.julia/environments/v1.6/Project.toml`  
[438e738f] + PyCall v1.92.3  
Updating `~/.julia/environments/v1.6/Manifest.toml`  
[8f4d0f93] + Conda v1.5.1  
[682c06a0] + JSON v0.21.1  
[1914dd2f] + MacroTools v0.5.6  
[69de0a69] + Parsers v1.1.0  
[438e738f] + PyCall v1.92.3  
[81def892] + VersionParsing v1.2.0  
[2a0f44e3] + Base64  
[ade2ca70] + Dates  
[8f399da3] + Libdl  
[37e2e46d] + LinearAlgebra  
[d6f4376e] + Markdown  
[a63ad114] + Mmap  
[de0858da] + Printf  
[9a3f8284] + Random  
[9e88b42a] + Serialization  
[4ec0a83e] + Unicode  
Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/6231e40619c15148bcb80aa19d731e629877d762/build.log`  
Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/169bb8ea6b1b143c5cf57df6d34d022a7b60c6db/build.log`  
ERROR: Error building `PyCall`:  
Traceback (most recent call last):  
File “/home/marllos/.julia/packages/PyCall/BD546/deps/find\_libpython.py”, line 33, in   
import ctypes.util  
File “/usr/local/lib/python3.9/ctypes/ **init**.py”, line 8, in   
from \_ctypes import Union, Structure, Array  
ModuleNotFoundError: No module named '_ctypes’  
ERROR: LoadError: failed process: Process(setenv(`python3 /home/marllos/.julia/packages/PyCall/BD546/deps/find_libpython.py --list-all`,[“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin”, “PWD=/home/marllos”, “XDG\_SESSION\_CLASS=user”, “LESSOPEN=| /usr/bin/lesspipe %s”, “SHELL=/bin/bash”, “SSH\_CONNECTION=200.136.244.11 58299 200.136.245.156 22”, “OPENBLAS\_NUM\_THREADS=8”, “DBUS\_SESSION\_BUS\_ADDRESS=unix:path=/run/user/1003/bus”, “MOTD\_SHOWN=pam”, “LANG=en\_US.UTF-8” … "_=/usr/local/bin/julia", “JULIA\_LOAD\_PATH=@:/tmp/jl\_RdnWJ4”, “USER=marllos”, “SSH\_TTY=/dev/pts/0”, “LESSCLOSE=/usr/bin/lesspipe %s %s”, “HOME=/home/marllos”, “TERM=xterm”, "LS\_COLORS=rs=, …“PYTHONIOENCODING=UTF-8”]), ProcessExited(1)) [1]

Stacktrace:  
[1] pipeline\_error  
@ ./process.jl:525 [inlined]  
[2] (::Base.var"#644#645"{Base.Process})()  
@ Base ./process.jl:319  
[3] iterate(itr::Base.EachLine{Base.PipeEndpoint}, state::Nothing) (repeats 2 times)  
@ Base ./io.jl:1014  
[4] \_collect(cont::UnitRange{Int64}, itr::Base.EachLine{Base.PipeEndpoint}, #unused#::Base.HasEltype, isz::Base.SizeUnknown)  
@ Base ./array.jl:613  
[5] collect  
@ ./array.jl:602 [inlined]  
[6] #readlines#340  
@ ./io.jl:551 [inlined]  
[7] readlines  
@ ./io.jl:551 [inlined]  
[8] exec\_find\_libpython  
@ ~/.julia/packages/PyCall/BD546/deps/buildutils.jl:28 [inlined]  
[9] find\_libpython(python::String; \_dlopen::typeof(Base.Libc.Libdl.dlopen))  
@ Main ~/.julia/packages/PyCall/BD546/deps/buildutils.jl:43  
[10] find\_libpython(python::String)  
@ Main ~/.julia/packages/PyCall/BD546/deps/buildutils.jl:41  
[11] top-level scope  
@ ~/.julia/packages/PyCall/BD546/deps/build.jl:87  
[12] include(fname::String)  
@ Base.MainInclude ./client.jl:444  
[13] top-level scope  
@ none:5  
in expression starting at /home/marllos/.julia/packages/PyCall/BD546/deps/build.jl:43

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 15, 2021, 6:59pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/10 "2021-04-15T18:59:31Z")

</div>

I did and it said I already had the latest version.

$ sudo apt-get install libffi-dev  
Reading package lists… Done  
Building dependency tree  
Reading state information… Done  
libffi-dev is already the newest version (3.3-4).  
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 15, 2021, 7:30pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/11 "2021-04-15T19:30:36Z")

</div>

Did you clone cpython and do

```julia
./configure
make # alternatively `make -j 4` will utilize 4 threads
sudo make altinstall

```

?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 15, 2021, 7:35pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/12 "2021-04-15T19:35:26Z")

</div>

Alternatively, did you do what SGJ said:

```julia
julia> ENV["PYTHON"]=""

pkg> build PyCall

```

I’m not sure what’s wrong with Ubuntu’s Python, but apparently you are not the only one with the issue. Doing the above will let PyCall grab a new Python via Conda. Then you don’t have to worry about the state of Ubuntu’s Python or have to build your own.

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 15, 2021, 8:02pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/13 "2021-04-15T20:02:53Z")

</div>

> [@mkitti](#):
>
> Doing the above will let PyCall grab a new Python via Conda.

Will each user get a copy of Python via Conda in ~/.julia, or if I do it for myself, does it apply to everyone?

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 16, 2021, 2:46pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/14 "2021-04-16T14:46:26Z")

</div>

One thing I only just noticed is that python3 points to python3.9 (3.9.4). And the “import ctypes.util” command works in python3.8. Just to clarify, I’m not asking for help to fix Julia bugs, but to fix the infrastructure needed for Julia. Thank you.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 16, 2021, 3:49pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/15 "2021-04-16T15:49:05Z")

</div>

OK, does this work?

```julia
julia> ENV["PYTHON"] = "/usr/bin/python3.8" # Use which to locate python3.8

julia> Pkg.build("PyCall")

```

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 16, 2021, 4:52pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/16 "2021-04-16T16:52:19Z")

</div>

Thank you very much mkitti. Your tip worked very well. I saved it in ~/.julia/config.

---

<div class="post-metadata">

**Author:** ![marllos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marllos/32/205917_2.png) [@marllos](https://discourse.julialang.org/u/marllos)\
**Post date:** [April 16, 2021, 5:01pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/17 "2021-04-16T17:01:09Z")

</div>

The [link](https://bugs.python.org/issue42580) seems to say something about my topic, stating that there is no error in python3.9 regarding ctypes.util.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 16, 2021, 5:11pm UTC](https://discourse.julialang.org/t/build-pycall-error/59252/18 "2021-04-16T17:11:01Z")

</div>

I would probably check with the package maintainer for however you obtained Python 3.9.4. For example:

[https://launchpad.net/ubuntu/+source/python3.9/+bugs](https://launchpad.net/ubuntu/+source/python3.9/+bugs)
