python.net import clr throws invalid pointer error
Question: When i am trying to import clr in my python code i get the following error:

    
    
    *** Error in `python': free(): invalid pointer: 0xb0f1a120 ***
    Stacktrace:
    
      at <unknown> <0xffffffff>
      at (wrapper managed-to-native) Python.Runtime.Runtime.Py_Initialize () <0xffffffff>
      at Python.Runtime.Runtime.Initialize () <0x00023>
      at Python.Runtime.PythonEngine.Initialize () <0x00047>
      at Python.Runtime.PythonEngine.InitExt () <0x0000b>
      at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
    
    Native stacktrace:
    
        /usr/lib/libmonoboehm-2.0.so.1(+0xcb5f4) [0xb1b5e5f4]
        [0xb7745d14]
        [0xb7745d1e]
        /lib/i386-linux-gnu/libc.so.6(gsignal+0x47) [0xb7592607]
        /lib/i386-linux-gnu/libc.so.6(abort+0x143) [0xb7595a33]
        /lib/i386-linux-gnu/libc.so.6(+0x68e53) [0xb75cce53]
        /lib/i386-linux-gnu/libc.so.6(+0x7333a) [0xb75d733a]
        /lib/i386-linux-gnu/libc.so.6(+0x73fad) [0xb75d7fad]
        /usr/lib/i386-linux-gnu/libpython2.7.so(PyString_InternInPlace+0x97) [0xb0b3a157]
        /usr/lib/i386-linux-gnu/libpython2.7.so(PyString_InternFromString+0x2f) [0xb0ad78ef]
        /usr/lib/i386-linux-gnu/libpython2.7.so(PyType_Ready+0xb50) [0xb0b356e0]
        /usr/lib/i386-linux-gnu/libpython2.7.so(_Py_ReadyTypes+0xcd) [0xb0b3d47d]
        /usr/lib/i386-linux-gnu/libpython2.7.so(Py_InitializeEx+0x6d) [0xb0b5d5dd]
        /usr/lib/i386-linux-gnu/libpython2.7.so(Py_Initialize+0x1b) [0xb0b5df7b]
        [0xb481553c]
        [0xb4814f2c]
        [0xb480af98]
        [0xb480ae84]
        [0xb480af0d]
        /usr/lib/libmonoboehm-2.0.so.1(+0x29723) [0xb1abc723]
    
    Debug info from gdb:
    
    Could not attach to process.  If your uid matches the uid of the target
    process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
    again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
    ptrace: Operation not permitted.
    No threads.
    
    =================================================================
    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
    used by your application.
    =================================================================
    

I found a reference to a similar problem
(<https://mail.python.org/pipermail/pythondotnet/2014-October/001598.html>)
but i can not figure out how to use the npython binary for example and i do
not wish to rebuild python with shared-library enabled.

Any hints or help will be greatly appreciated.


Answer: After some painful trials i achieved using `import clr` successfully in my
code.

First i needed somehow to use the right binaries and in order to achieve that
i used the latest development source from git of the pythonnet/pythonnet
package.

You can try: `$ sudo pip install --pre pythonnet` that downloads and installs
the latest development source. But keep in mind there are some perquisites so
i am attaching the travis build details

    
    
    system_info
    Build language: python
    Operating System:   Ubuntu 12.04 LTS
    $ python --version
    Python 2.7.9
    $ pip --version
    pip 6.0.7 from /home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages (python 2.7)
    $ sudo apt-get install software-properties-common
    $ sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
    $ sudo apt-get -qq install mono-devel mono-gmcs mono-xbuild nunit-console
    $ sudo mozroots --import --machine --sync
    $ yes | sudo certmgr -ssl -m https://go.microsoft.com
    $ yes | sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
    $ yes | sudo certmgr -ssl -m https://nuget.org
    $ pip install six
    

Now normally installing pythonnet with pip should execute successfully and you
can try calling import clr in your python code. In my case personally it
failed even in this scenario although it was installing without errors. The
reason was that although my python was compiled without --enable-shared,
running

    
    
    $ python -c 'import sys; from distutils.sysconfig import get_config_var; print(get_config_var("Py_ENABLE_SHARED"))'
    

returned 1 although it should return 0.

So i downloaded the latest dev-source from git
<https://github.com/pythonnet/pythonnet>

and after putting it in the right folder i edited setup.py setting the
variable that was checking for the shared libraries to 0, after that executing

    
    
    $ sudo python setup.py install
    

the script installed successfully without error and i could use import clr in
my python scripts. To make sure everything runs correctly you can run:

    
    
    $ python src/tests/runtests.py
    

