Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuitka error Cannot find ' ' in package ' ' as absolute import

Tags:

python

nuitka

I'm trying to use the nuitka tool to turn my python program into executable on ubuntu. It works fine if the program doesn't have any import statements but breaks when I use it on a program that imports something e.g.

test.py

import numpy

print "hello, world."

type this on commandline

nuitka --recurse-all --python-version=2.7 test.py

and gives me these errors

Nuitka:WARNING:/usr/lib/python2.7/dist-packages/numpy/numarray/functions.py:45: Cannot find 'copyreg' in package 'numpy.numarray' as absolute import.
Nuitka:WARNING:/usr/lib/python2.7/dist-packages/numpy/distutils/npy_pkg_config.py:11: Cannot find 'configparser' in package 'numpy.distutils' as absolute import.
Nuitka:WARNING:/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:1765: Cannot find 'Numeric' in package 'numpy.distutils' as absolute import.
Nuitka:WARNING:/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:1770: Cannot find 'numarray' in package 'numpy.distutils' as absolute import.
Nuitka:WARNING:/usr/lib/python2.7/dist-packages/numpy/f2py/diagnose.py:48: Cannot find 'numpy_distutils' in package 'numpy.f2py' as absolute import.
Nuitka:WARNING:/usr/lib/python2.7/dist-packages/numpy/f2py/diagnose.py:87: Cannot find 'numpy_distutils.command.build_flib' in package 'numpy.f2py' as absolute import.
like image 472
bakalolo Avatar asked Jun 08 '16 21:06

bakalolo


1 Answers

I don't know about your particular use case but I also faced similar Cannot find '' in Package errors when using nuitka.

I was using sqlalchemy and had a similar issue with configparser.
After about a day of debugging I found out that Nuitka trips up with SWIG (Dynamically Loaded shared objects). What it means basically is, some programs/modules try to increase compatibility by using conditional imports.
For eg:

If python_version==3.5:
    import thislibrary
else:
    import thatlibrary

specifically the configparser library is named configparser in python3 and ConfigParser in python2.
So what basically is happening is that nuitka is trying to import python 3 stuff when you clearly are using python 2.

For me the fix was to modify the source code of sqlalchemy and change the if else construct to:

import thatlibrary   

You can find more information in this Guide written by Tom Sheffler

like image 110
ChaoticTwist Avatar answered Oct 08 '22 01:10

ChaoticTwist