question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SystemError: initialization of _heapq did not return an extension module

See original GitHub issue

I’m experiencing the same error mentioned by @sirgogo in #88 .

oliver@oliver-arch:~ % ipython
Python 3.5.5 |Anaconda, Inc.| (default, Mar 12 2018, 23:12:44) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import julia

In [2]: j = julia.Julia()
Error processing line 1 of /home/oliver/local/miniconda3/lib/python3.5/site-packages/PyUtilib-5.4.1-py2.7-nspkg.pth:

Failed to import the site module
Traceback (most recent call last):
  File "/home/oliver/local/miniconda3/lib/python3.5/site.py", line 167, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/home/oliver/local/miniconda3/lib/python3.5/types.py", line 166, in <module>
    import functools as _functools
  File "/home/oliver/local/miniconda3/lib/python3.5/functools.py", line 21, in <module>
    from collections import namedtuple
  File "/home/oliver/local/miniconda3/lib/python3.5/collections/__init__.py", line 29, in <module>
    import heapq as _heapq
  File "/home/oliver/local/miniconda3/lib/python3.5/heapq.py", line 587, in <module>
    from _heapq import *
SystemError: initialization of _heapq did not return an extension module

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/oliver/local/miniconda3/lib/python3.5/site.py", line 559, in <module>
    main()
  File "/home/oliver/local/miniconda3/lib/python3.5/site.py", line 541, in main
    known_paths = addsitepackages(known_paths)
  File "/home/oliver/local/miniconda3/lib/python3.5/site.py", line 318, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/home/oliver/local/miniconda3/lib/python3.5/site.py", line 206, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/home/oliver/local/miniconda3/lib/python3.5/site.py", line 177, in addpackage
    import traceback
  File "/home/oliver/local/miniconda3/lib/python3.5/traceback.py", line 3, in <module>
    import collections
  File "/home/oliver/local/miniconda3/lib/python3.5/collections/__init__.py", line 29, in <module>
    import heapq as _heapq
  File "/home/oliver/local/miniconda3/lib/python3.5/heapq.py", line 587, in <module>
    from _heapq import *
SystemError: initialization of _heapq did not return an extension module

I’m running Arch Linux and using the following versions:

Package Version
python 3.5.5 :: Anaconda, Inc.
julia 0.6.2
PyJulia 0.1.5
PyCall 1.15.0

Any advice is appreciated!

Thanks, Oliver

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
randy3kcommented, May 26, 2018

I have a similar issue on my conda python, but not the homebrew python.

It may be because JuliaCall fails to detect if (anaconda/miniconda) python has been initialized.

I got the following from my miniconda python

In [1]: import ctypes

In [2]: libpython = ctypes.PyDLL("/Users/Randy/miniconda3/lib/libpython3.6m.dylib")

In [3]: libpython.Py_IsInitialized()
Out[3]: 0

I got the following from my homebrew python

In [1]: import ctypes

In [2]: libpython = ctypes.PyDLL("/usr/local/Cellar/python3/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib")

In [3]: libpython.Py_IsInitialized()
Out[4]: 1

UPDATE:

The following code works in miniconda python

In [1]: import ctypes

In [2]: libpython = ctypes.CDLL(None)

In [3]: libpython.Py_IsInitialized()
Out[3]: 1

And it seems that PyCall already loads in process symbols https://github.com/JuliaPy/PyCall.jl/pull/293 Not sure the reason now.

0reactions
sblinz-zzcommented, Nov 5, 2018

Removing ~/.julia/lib/v0.6/PyCall.jl worked for me. System info below:

OS: Ubuntu 16.04 (running inside a Docker container) Julia: 0.6 Python: 3.5.2 Virtual Environment: Conda (rllab, https://github.com/rll/rllab/blob/master/environment.yml)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python crash when boost/c++ is imported if anaconda was used
It turns out the error isn't specifically with Py_Initialize() , but with the symbolic linkage between program and python runtime.
Read more >
initialization of _heapq did not return an extension module
I'm experiencing the same error mentioned by @sirgogo in #88 . oliver@oliver-arch:~ % ipython Python 3.5.5 |Anaconda, Inc.| (default, ...
Read more >
Python crash when boost/c++ is imported if anaconda was used
SystemError : initialization of _heapq did not return an extension module. Sys/build details: Mac OS Mojave, 10.14.6 Python version 3.7.4, Conda 4.8.3 C++...
Read more >
heapq — Heap queue algorithm — Python 3.11.1 ...
Source code: Lib/heapq.py This module provides an implementation of the heap ... as a regular Python list without surprises: heap[0] is the smallest...
Read more >
Efficiency for calling Julia from python and purely run Julia
python3.8/heapq.py", line 581, in <module> from _heapq import * SystemError: initialization of _heapq did not return an extension module.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found