Pomegranate: import pomegranate from python3 fail with Ubuntu 16.04

Created on 16 Aug 2017  路  12Comments  路  Source: jmschrei/pomegranate

After installing pomegranate on Ubuntu 16.04 with
sudo pip3 install pomegranate

I get the following error message when I try to import pomegranate

import pomegranate
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.5/dist-packages/pomegranate/__init__.py", line 9, in
from .base import *
File "pomegranate/base.pyx", line 1, in init pomegranate.base (pomegranate/base.c:11221)
ImportError: No module named 'pomegranate.utils'

Please any help with this?

Most helpful comment

What happens if you use pip to install instead of pip3?

I resume here what I tried. Before each point I purge all pomegranate files and folders, finding them by sudo updatedb locate pomegranate. My goal is use pomegranate in python3.

  1. purged all pomegranate files
    sudo git clone https://github.com/jmschrei/pomegranate.git
    cd pomegranate
    sudo python setup.py install
    python2.7 error: ImportError: No module named base
    python3 error: ImportError: No module named 'pomegranate.base'

  2. purged all pomegranate files
    sudo git clone https://github.com/jmschrei/pomegranate.git
    cd pomegranate
    sudo python3 setup.py install
    output with error:

    Unable to find pgen, not compiling formal grammar.
    warning: no files found matching 'Doc/*'
    warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Utility'
    Installed /home/francesco/scripts/pomegranate/.eggs/Cython-0.26-py3.5-linux-x86_64.egg
    running install
    running bdist_egg
    running egg_info
    creating pomegranate.egg-info
    writing pomegranate.egg-info/PKG-INFO
    writing top-level names to pomegranate.egg-info/top_level.txt
    writing dependency_links to pomegranate.egg-info/dependency_links.txt
    writing requirements to pomegranate.egg-info/requires.txt
    writing manifest file 'pomegranate.egg-info/SOURCES.txt'
    reading manifest file 'pomegranate.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'pomegranate/*.c'
    writing manifest file 'pomegranate.egg-info/SOURCES.txt'
    installing library code to build/bdist.linux-x86_64/egg
    running install_lib
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/__init__.py -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/base.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/bayes.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/distributions.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/utils.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    running build_ext
    building 'pomegranate.base' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/pomegranate
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-  prefix-map=/build/python3.5-MLq5fN/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -I/usr/local/lib/python3.5/dist-packages/numpy/core/include -c pomegranate/base.c -o build/temp.linux-x86_64-3.5/pomegranate/base.o
    x86_64-linux-gnu-gcc: error: pomegranate/base.c: No such file or directory
    x86_64-linux-gnu-gcc: fatal error: no input files
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
  3. purged all pomegranate files
    sudo pip install pomegranate --no-cache-dir
    installation OK in python 2.7.
    No module found in python3.

  4. purged all pomegranate files
    sudo pip3 install pomegranate --no-cache-dir
    python2.7 : no module found.
    python3 error as above:

    ImportError                               Traceback (most recent call last)
    <ipython-input-1-f115d95d8f94> in <module>()
    ----> 1 import pomegranate
    /usr/local/lib/python3.5/dist-packages/pomegranate/__init__.py in <module>()
          7 """ 
          8  
    ----> 9 from .base import * 
         10 from .parallel import * 
         11 
    /usr/local/lib/python3.5/dist-packages/pomegranate/base.pyx in init pomegranate.base (pomegranate/base.c:11221)()
    ----> 1 # base.pyx
          2 # Contact: Jacob Schreiber ( [email protected] )
          3 
          4 from .utils cimport *
          5 
     ImportError: No module named 'pomegranate.utils'
    

All 12 comments

This can happen when you have an older version of pomegranate already installed and messes with the install. Can you try deleting pomegranate completely from your computer (including manually from site-packages) and reinstalling it?

I did:

sudo pip3 uninstall pomegranate
sudo pip3 install pomegranate --no-cache-dir

but I still have the same error message.

I'm having the same problem with pip3. I uninstalled, cleaned everything by hand, re-installed (with --no-cache-dir) but the problem is still there.

I see 114 and 215.
numpy could be the problem (but I cannot downgrade it now as suggested in 215): I have numpy 1.13.1, and 1.12.0 was already problematic. Is there a chance to solve this? Thank you.

I installed on different computer with Ubuntu 16.04. On some computer pomegranate look to work fine but on other not. I checked the numpy version it's all 1.13.1

I don't immediately know what the issue could be. Are you -positive- that you've removed all remnants of pomegranate before upgrading? There might be an egg file or something hanging around. Can you also try cloning from github and letting me know if that works?

I uninstalled both with pip uninstall pomegranate and pip3 uninstall pomegranate. Then removed by hand all the output files of sudo find / -name pomegra*, until it gives no output. Then run sudo pip3 install pomegranate --no-cache-dir. Then in ipython3 the import pomegranate gives the error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-f115d95d8f94> in <module>()
----> 1 import pomegranate
/usr/local/lib/python3.5/dist-packages/pomegranate/__init__.py in <module>()
      7 """ 
      8  
----> 9 from .base import * 
     10 from .parallel import * 
     11 
/usr/local/lib/python3.5/dist-packages/pomegranate/base.pyx in init pomegranate.base (pomegranate/base.c:11221)()
----> 1 # base.pyx
      2 # Contact: Jacob Schreiber ( [email protected] )
      3 
      4 from .utils cimport *
      5 
 ImportError: No module named 'pomegranate.utils'

I purged all files again, cloned from github, then sudo python3 setup.py install gives the error like in 314 :

creating build/temp.linux-x86_64-3.5/pomegranate 
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-MLq5fN/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -I/usr/local/lib/python3.5/dist-packages/numpy/core/include -c pomegranate/base.c -o build/temp.linux-x86_64-3.5/pomegranate/base.o
x86_64-linux-gnu-gcc: error: pomegranate/base.c: No such file or directory
x86_64-linux-gnu-gcc: fatal error: no input files
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

If you clone from github, you need to go into the folder and type in python setup.py install.

What happens if you use pip to install instead of pip3?

What happens if you use pip to install instead of pip3?

I resume here what I tried. Before each point I purge all pomegranate files and folders, finding them by sudo updatedb locate pomegranate. My goal is use pomegranate in python3.

  1. purged all pomegranate files
    sudo git clone https://github.com/jmschrei/pomegranate.git
    cd pomegranate
    sudo python setup.py install
    python2.7 error: ImportError: No module named base
    python3 error: ImportError: No module named 'pomegranate.base'

  2. purged all pomegranate files
    sudo git clone https://github.com/jmschrei/pomegranate.git
    cd pomegranate
    sudo python3 setup.py install
    output with error:

    Unable to find pgen, not compiling formal grammar.
    warning: no files found matching 'Doc/*'
    warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Utility'
    Installed /home/francesco/scripts/pomegranate/.eggs/Cython-0.26-py3.5-linux-x86_64.egg
    running install
    running bdist_egg
    running egg_info
    creating pomegranate.egg-info
    writing pomegranate.egg-info/PKG-INFO
    writing top-level names to pomegranate.egg-info/top_level.txt
    writing dependency_links to pomegranate.egg-info/dependency_links.txt
    writing requirements to pomegranate.egg-info/requires.txt
    writing manifest file 'pomegranate.egg-info/SOURCES.txt'
    reading manifest file 'pomegranate.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'pomegranate/*.c'
    writing manifest file 'pomegranate.egg-info/SOURCES.txt'
    installing library code to build/bdist.linux-x86_64/egg
    running install_lib
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/__init__.py -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/base.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/bayes.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/distributions.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    copying pomegranate/utils.pxd -> build/lib.linux-x86_64-3.5/pomegranate
    running build_ext
    building 'pomegranate.base' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/pomegranate
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-  prefix-map=/build/python3.5-MLq5fN/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -I/usr/local/lib/python3.5/dist-packages/numpy/core/include -c pomegranate/base.c -o build/temp.linux-x86_64-3.5/pomegranate/base.o
    x86_64-linux-gnu-gcc: error: pomegranate/base.c: No such file or directory
    x86_64-linux-gnu-gcc: fatal error: no input files
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
  3. purged all pomegranate files
    sudo pip install pomegranate --no-cache-dir
    installation OK in python 2.7.
    No module found in python3.

  4. purged all pomegranate files
    sudo pip3 install pomegranate --no-cache-dir
    python2.7 : no module found.
    python3 error as above:

    ImportError                               Traceback (most recent call last)
    <ipython-input-1-f115d95d8f94> in <module>()
    ----> 1 import pomegranate
    /usr/local/lib/python3.5/dist-packages/pomegranate/__init__.py in <module>()
          7 """ 
          8  
    ----> 9 from .base import * 
         10 from .parallel import * 
         11 
    /usr/local/lib/python3.5/dist-packages/pomegranate/base.pyx in init pomegranate.base (pomegranate/base.c:11221)()
    ----> 1 # base.pyx
          2 # Contact: Jacob Schreiber ( [email protected] )
          3 
          4 from .utils cimport *
          5 
     ImportError: No module named 'pomegranate.utils'
    

I was seeing this error in this situation:

  • I have installed pomegranate via pip
  • I have pomegranate repo cloned and
  • I am on the base path of the cloned repo

In that case, ipython will try to load modules from current folder, which otherwise should be loaded from the installed path.

@fpdx Can you try running ipython from a different folder, so that import paths do not mix?

:| This is super frustrating. As @tuxdna shows in another issue, if you can set up a virtual env it'll end up working. Maybe a temporary work-around is to use a virtualenv, pip install pomegranate, and manually copy the file over to your main environment? I know that sounds sucky to do but it might end up working...

The creation of Mac and Linux wheels should solve this issue. Re-open if the problem persists.

Was this page helpful?
0 / 5 - 0 ratings