简体   繁体   中英

Module can be imported from build directory but not from installed directory

This is encountered on Ubuntu 16.04.2, with GCC 5.4.0 and Python 3.5.2. So I built a module and inside the build directory I can easily import it without problem:

➜  build git:(master) ✗ python3 -c "import foo"
➜  build git:(master) ✗ 

However, when I install the module into install_dir (the module was built with cmake/make and then make install --prefix=$install_dir ) and add its location into PYTHONPATH , it doesn't work:

➜  ~ cd
➜  ~ echo $PYTHONPATH
$install_dir/lib/python3.5/site-packages:/usr/local/lib/python3.5/site-packages:
➜  ~ python3 -c "import foo"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "$install_dir/lib/python3.5/site-packages/foo/__init__.py", line 17, in <module>
    from . import cpp
  File "$install_dir/lib/python3.5/site-packages/foo/cpp/__init__.py", line 43, in <module>
    exec("from . import %s" % module_name)
  File "<string>", line 1, in <module>
  File "$install_dir/lib/python3.5/site-packages/foo/cpp/common.py", line 21, in <module>
    _common = swig_import_helper()
  File "$install_dir/lib/python3.5/site-packages/foo/cpp/common.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
SystemError: initialization of _common raised unreported exception

Note: naming has been changed to make the case more generous. The funny thing is I ran the same script for 3 different devices with the fresh installed OS, only 1 has this problem (!).

What could be the main cause here that I can investigate further? Or is this something funny caused by Python 3?

Run into this problem today.

The solution for me was:

  • upgrade petsc (3.7.3->3.7.6) and slepc (3.7.3->3.7.4)
  • reinstall petsc4py (3.7.0) and slepc4py (3.7.0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM