(solved: unknown) ModuleNotFoundError: No module named 'pivy._coin'

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
PMac
Posts: 135
Joined: Sat Sep 02, 2017 10:44 pm

(solved: unknown) ModuleNotFoundError: No module named 'pivy._coin'

Post by PMac »

Hi, am attempting to compile FC latest pull on Linuxmint and am off yet again down another compiler rabbit hole. The reported issue has been around for a while.

pivy._coin is being reported as missing as below
-- Checking for module 'Coin'
-- Found Coin, version 4.0.1
-- Coin3D libraries found
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pivy/coin.py", line 23, in swig_import_helper
return importlib.import_module(mname)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pivy._coin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pivy/__init__.py", line 30, in <module>
from .coin import SoDB, SoNodeKit, SoInteraction
File "/usr/lib/python3/dist-packages/pivy/coin.py", line 26, in <module>
_coin = swig_import_helper()
File "/usr/lib/python3/dist-packages/pivy/coin.py", line 25, in swig_import_helper
return importlib.import_module('_coin')
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_coin'
Balance of compile appears OK.

Pivy is installed at /usr/lib/python3/dist-packages/pivy/.

/usr/lib/ currently has python2.7, python3, python3.8 and python3.9 folders.

The compile process as part of the Coin3D compile initially correctly finds the installed pivy at python3 (the current default python for is 3.8.10) and finally tries to find pivy._coin in the latest python version as installed on my machine at python3.9/importlib where the reported exception occurs.

From the tracebacks shown the compile process jumps around the various installed python versions and loses track of the fact that the already located pivy._coin actually lives under the python3 folder.

The compile command (out of source) is
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=Debug ../freecad-source
No obvious errors are reported in the cmake compile log. A copy of the console output during compile is attached.
FCCompileConsoleOutput.txt
(12.1 KiB) Downloaded 39 times

Pivy was removed and reinstalled via 'sudo apt install python3-pivy' in an unsuccessful attempt to correct this issue.

As an aside this appears to be similar to the recently fixed Shiboken issues where Shiboken couldn't decide which python 3 folder it was going to use when compiling. I understand it had to be forced to utilise python3.8.

Any ideas/comments on way forward to correct this pivy problem?

And the required bleeding-edge info:

Code: Select all

OS: Linux Mint 20.3 (X-Cinnamon/cinnamon2d)
Word size of FreeCAD: 64-bit
Version: 0.20.28612 (Git)
Build type: Debug
Branch: master
Hash: 9b3a50840f39f038bfae8c7b41f76fef7017a96e
Python 3.8.10, Qt 5.12.8, Coin 4.0.1, OCC 7.3.0
Locale: English/New Zealand (en_NZ)
Installed mods: 
  * BIM
Last edited by PMac on Wed Apr 06, 2022 4:02 pm, edited 1 time in total.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: ModuleNotFoundError: No module named 'pivy._coin'

Post by looo »

pivy needs to be build for every python version. As your default python version is 3.8, maybe pivy is build for python3.8?
Syres
Veteran
Posts: 2899
Joined: Thu Aug 09, 2018 11:14 am

Re: ModuleNotFoundError: No module named 'pivy._coin'

Post by Syres »

PMac wrote: Sun Apr 03, 2022 1:30 pm /usr/lib/ currently has python2.7, python3, python3.8 and python3.9 folders.
Looks like you are in a similar situation as I was a long while ago, using a version of Python that's not the latest one on your system (I only use Python 3.9.x to communicate with Blender from my Conda FC) but use Python 3.6.9 for everything else. The way I hack my system is to overwrite https://github.com/FreeCAD/FreeCAD/blob ... cmake#L118 after the git pull line in my bash script, probably against all good practice, you have been warned!!

This should be done with the order that you want cmake to find the correct Python version on your own system so I'm guessing yours would be:

Code: Select all

        set(Python_ADDITIONAL_VERSIONS ${Python_ADDITIONAL_VERSIONS} "3.8" "3.9" "3.10" "3.7" "3.6")
or just leave 3.8 in there if you're in doubt, good luck.
PMac
Posts: 135
Joined: Sat Sep 02, 2017 10:44 pm

Re: ModuleNotFoundError: No module named 'pivy._coin'

Post by PMac »

Gentlemen, thanks for your prompt replies.

Syres, liked and tried your option without any success. Unfortunately line 118 and subsequent lines reside in an if statement for cmake version <= 3.12. Current cmake is 3.18.2 so a modified line 118 is never executed. I like the idea to easily modify the script.

Looo, looks like your suggested option is the way to go but am having real trouble compiling Coin/Pivy per python version. Needs SoQt, which according to the github source has been superceded by by Coin/Quarter. Looking at the FC wiki on Coin/Pivy compiling it seems to me that the instructions there are maybe dated. Currently am trying to get Quarter to compile locally for any python version. Am slowly working through compile errors as they arise.

It would be easy if I could do a specific python version install along the lines of

Code: Select all

sudo apt install Python3-pivy <for-a-specific-python-version>
to get Pivy as Looo suggests is required for each version of Python3.

Again thanks to both of you for your current help, will report further if I manage to progress this issue.
PMac
Posts: 135
Joined: Sat Sep 02, 2017 10:44 pm

Re: ModuleNotFoundError: No module named 'pivy._coin'

Post by PMac »

An update:
Still plodding through this rabbit hole and chipping away.

Have culled (removed and installed only one alternative) python3 update-alternatives so that python3 only has only one auto choice as python3.8.10.
Whereas previously I only had Python 2.7, 3, 3.8 and 3.9 versions, now have added versions 3.7, 3.10, 3.11 for this testing.

I note that when trying to compile FC, the Python version is reported as Python 3.8.10. That's what I'd expect.

Code: Select all

==============
Summary report
==============

-- Build type:          Debug
-- Compiler:            /usr/bin/c++ (9.4.0)
-- Flags:               -Wall -Wextra -Wno-write-strings 
-- Standard:            Requires C++17
-- Python:              3.8.10 [/usr/bin/python3] [.cpython-38-x86_64-linux-gnu]
-- PCL:                 not enabled
-- pybind11:            not enabled
-- Boost:               1.78.0 (1.78.0)
...
But when the Coin/Pivy part of the compile is processed during the compile the importlib is still being imported from Python3.9 and the error 'Module not found: pivy._coin'. Relevant code is below from /usr/lib/python3/dist-packages/coin.py. '_swig_python_version_info' contains the default 3.8.10, but a couple of lines lines below the 'import importlib' is from python3.9.

Yet to track down why does python change from the reported 3.8 to 3.9? Have totally deleted build folder content in case of stale settings, with same results.

Code: Select all

from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
    def swig_import_helper():
        import importlib
In parallel, I have not been able to separately compile pivy for any python version. Still utilising Coin/Pivy as installed under python3/dist-packages via 'sudo apt install python3-pivy'. Am at a loss how to make an install or compile of the python3-pivy module happen for a specified python version as Looo suggested.
PMac
Posts: 135
Joined: Sat Sep 02, 2017 10:44 pm

Re: ModuleNotFoundError: No module named 'pivy._coin'

Post by PMac »

Another day!

I've removed and re-installed python3-pivy, often ditched the stale compiler files, have done regular git pulls on FC and restarted the machine more than a few times in the past few days. All without any effect on the reported issues.

Blow me down! Pivy now appears in the summary report as was expected when I compile with the previously listed compile command.

Code: Select all

-- Coin3D:              4.0.1 [Coin;GL;Xext;SM;ICE;X11;dl;pthread] [/usr/local/include;/usr/local/include/Inventor/annex]
-- Pivy:                0.6.5
I'd been doing some deep reading about python conditional imports and suspect that something has been changed in the code. The FC code is a clean clone on my local machine without any backdoor changes by myself. I do however note that many FC files have been updated in recent git pulls and may have inadvertently corrected the initially reported lack of Pivy.

Have just completed a new debug compile and a full 3/4 hour make without obvious errors.

Am now at build:

Code: Select all

OS: Linux Mint 20.3 (X-Cinnamon/cinnamon2d)
Word size of FreeCAD: 64-bit
Version: 0.20.28644 (Git)
Build type: Debug
Branch: master
Hash: b5a6970c5317f3b82788ea9646d3e80e356b36d5
Python 3.8.10, Qt 5.12.8, Coin 4.0.1, OCC 7.3.0
Locale: English/New Zealand (en_NZ)
Installed mods: 
  * BIM

So I'm going to mark this as solved: unknown. Thanks to all, am now off for a nap after which I'll look at FC for new rabbit holes to explore.
Post Reply