tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.32k stars 372 forks source link

ImportError: No module named OCC.TColgp #444

Closed brunozilli closed 6 years ago

brunozilli commented 7 years ago

Hello Thomas,

Please just read these few comments and give me a your idea.

I've tried to install python-occ with conda python 2.7 and it seems that all was fine. No error message during installation. After this, I compiled pygear.py by python 2.7 and it worked with non error messages.

Then, I launched pygear but it returned me a message:

caelinux@Bruno:~/Documenti/pygear-0.24$ python /usr/local/lib/python2.7/dist-packages/pygear.py Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/pygear.py", line 37, in from OCC.TColgp import TColgp_Array1OfPnt2d, TColgp_Array1OfPnt ImportError: No module named OCC.TColgp

Thank you very much for your help and ideas.

Bruno

tpaviot commented 7 years ago

Which pythonocc version did you install ?

brunozilli commented 7 years ago

caelinux@Bruno:/usr/local/lib/python2.7/dist-packages$ python Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2

brunozilli commented 7 years ago

sorry, pythonocc-018

I used this command line

conda install -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core==0.18

Anaconda 4.4.0 with python 2.7

Thank you

tpaviot commented 7 years ago

@brunozilli try to import OCC.TColgp from a python prompt. btw, I don't know pygear and if it was updated to the latest pythonocc releases

tpaviot commented 6 years ago

No news about this issue, please @brunozilli reopen if needed

pedrogscruz commented 6 years ago

Same issue here

hiro2016 commented 5 years ago

Same with anaconda python3.5 but I got a feeling maybe it's due to some outdated code I used.

Jupyter QtConsole 4.3.1
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

from OCC.Core.gp import gp_Dir, gp_Ax2, gp_Circ, gp_Pnt
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-fc59bc42a444> in <module>()
----> 1 from OCC.Core.gp import gp_Dir, gp_Ax2, gp_Circ, gp_Pnt

ImportError: No module named 'OCC.Core' 

The below works

from OCC.Display.SimpleGui import init_display
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox

display, start_display, add_menu, add_function_to_menu = init_display()
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()

display.DisplayShape(my_box, update=True)
start_display()

conda activate v3.5;python filename_of_your_choice.py

Maybe irrelevant but the below sample code found at the official site does not work for python3 due to operator.div

# http://www.pythonocc.org/category/quick-examples/
import operator

import OCC.GProp
import OCC.BRepGProp

import ifcopenshell
import ifcopenshell.geom

import numpy

# RGBA colors for the visualisation of elements
RED, GRAY = (1,0,0,1), (0.6, 0.6, 0.6, 0.1)

# Model freely available at:
# http://www.nibs.org/?page=bsa_commonbimfiles
ifc_file = ifcopenshell.open("Duplex_A_20110907_optimized.ifc")

# Settings to specify usage of pyOCC
settings = ifcopenshell.geom.settings()
settings.set(settings.USE_PYTHON_OPENCASCADE, True)

# Some helper functions to map to the list of walls
def create_shape(elem):
    return ifcopenshell.geom.create_shape(settings, elem)

def calc_volume(s):
    props = OCC.GProp.GProp_GProps()
    OCC.BRepGProp.brepgprop_VolumeProperties(s.geometry, props)
    return props.Mass()

def calc_area(s):
    props = OCC.GProp.GProp_GProps()
    OCC.BRepGProp.brepgprop_SurfaceProperties(s.geometry, props)
    return props.Mass()

def normalize(li):
    mean, std = numpy.mean(li), numpy.std(li)
    return map(lambda v: abs(v-mean) / std, li)

# Obtain a list of walls from the model
walls = ifc_file.by_type("IfcWall")
# Create geometry for these walls
shapes = list(map(create_shape, walls))
# Calculate their volumes
volumes = map(calc_volume, shapes)
# Calculate their surface areas
areas = map(calc_area, shapes)
# Compose a feature from the two measures
feature = normalize(map(operator.div, areas, volumes))

# Initialize the viewer
pyocc_viewer = ifcopenshell.geom.utils.initialize_display()

# Loop over the sorted pairs of feature
# values and corresponding geometry
for d, s in sorted(zip(feature, shapes)):
    c = RED if d > 1. else GRAY
    ifcopenshell.geom.utils.display_shape(s, clr=c)

# Fit the model into view
pyocc_viewer.FitAll()

# Allow for user interaction
ifcopenshell.geom.utils.main_loop()

Install location?

d@mouse:~/anaconda3/pkgs$ ls |grep pythonocc
pythonocc-core-0.18.1-py35ha8ceefd_110
pythonocc-core-0.18.1-py35ha8ceefd_110.tar.bz2
pythonocc-core-0.18.1-py36hdfe9f0f_110
pythonocc-core-0.18.1-py36hdfe9f0f_110.tar.bz2
.
.
.
(v3.5) d@mouse:~/anaconda3/pkgs/pythonocc-core-0.18.1-py35ha8ceefd_110/lib/python3.5/site-packages$ ls
OCC

Obviously pip knows nothing about pythonocc as it's installed via conda:

conda activate v3.5
(v3.5) d@mouse:~/anaconda3/pkgs$ pip show pythonocc
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

anaconda-navigator has pythonocc listed as installed under the environment for python v3.5 env though.

Installation commands used

conda create --name v3.5 python=3.5
conda activate v3.5
conda install -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core==0.18.1  

sys.path

import sys

sys.path
Out[4]: 
['',
 '/home/d/anaconda3/envs/v3.5/lib/python35.zip',
 '/home/d/anaconda3/envs/v3.5/lib/python3.5',
 '/home/d/anaconda3/envs/v3.5/lib/python3.5/plat-linux',
 '/home/d/anaconda3/envs/v3.5/lib/python3.5/lib-dynload',
 '/home/d/.local/lib/python3.5/site-packages',
 '/home/d/anaconda3/envs/v3.5/lib/python3.5/site-packages',
 '/home/d/anaconda3/envs/v3.5/lib/python3.5/site-packages/IPython/extensions',
 '/home/d/.ipython']

Manually adding to search paths

import sys
sys.path.append("/home/d/anaconda3/pkgs/pythonocc-core-0.18.1-py35ha8ceefd_110/lib/python3.5/site-packages")
sys.path.append("/home/d/anaconda3/pkgs/pythonocc-core-0.18.1-py35ha8ceefd_110/lib/python3.5/site-packages/OCC")
import OCC.TColgp # No problem
from OCC.Display.SimpleGui import init_display # No problem
from OCC import * # No problem 
from OCC.Core import *
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-11-dc45e9568296> in <module>()
----> 1 from OCC.Core import *

ImportError: No module named 'OCC.Core'

Content of OCC folder

(v3.5) d@mouse:~/anaconda3/pkgs/pythonocc-core-0.18.1-py35ha8ceefd_110/lib/python3.5/site-packages/OCC$ ls
Adaptor2d.py             _BRepMesh.so        Geom2dConvert.py      _IntImpParGen.so   _RWStepGeom.so       _StlAPI.so
_Adaptor2d.so            BRepOffsetAPI.py    _Geom2dConvert.so     IntImp.py          RWStepRepr.py        StlMesh.py
Adaptor3d.py             _BRepOffsetAPI.so   Geom2dGcc.py          _IntImp.so         _RWStepRepr.so       _StlMesh.so
_Adaptor3d.so            BRepOffset.py       _Geom2dGcc.so         IntPatch.py        RWStepShape.py       StlTransfer.py
Addons.py                _BRepOffset.so      Geom2dHatch.py        _IntPatch.so       _RWStepShape.so      _StlTransfer.so
_Addons.so               BRepPrimAPI.py      _Geom2dHatch.so       IntPolyh.py        RWStepVisual.py      Storage.py
AdvApp2Var.py            _BRepPrimAPI.so     Geom2dInt.py          _IntPolyh.so       _RWStepVisual.so     _Storage.so
_AdvApp2Var.so           BRepPrim.py         _Geom2dInt.so         IntPoly.py         RWStl.py             Sweep.py
AdvApprox.py             _BRepPrim.so        Geom2dLProp.py        _IntPoly.so        _RWStl.so            _Sweep.so
_AdvApprox.so            BRepProj.py         _Geom2dLProp.so       IntRes2d.py        Select3D.py          TColGeom2d.py
AIS.py                   _BRepProj.so        Geom2d.py             _IntRes2d.so       _Select3D.so         _TColGeom2d.so
_AIS.so                  BRep.py             _Geom2d.so            Intrv.py           SelectBasics.py      TColGeom.py
AppBlend.py              _BRep.so            GeomAbs.py            _Intrv.so          _SelectBasics.so     _TColGeom.so
_AppBlend.so             BRepSweep.py        _GeomAbs.so           IntStart.py        SelectMgr.py         TColgp.py
AppCont.py               _BRepSweep.so       GeomAdaptor.py        _IntStart.so       _SelectMgr.so        _TColgp.so
_AppCont.so              BRepTools.py        _GeomAdaptor.so       IntSurf.py         ShapeAlgo.py         TCollection.py
AppDef.py                _BRepTools.so       GEOMAlgo.py           _IntSurf.so        _ShapeAlgo.so        _TCollection.so
_AppDef.so               BRepTopAdaptor.py   _GEOMAlgo.so          IntTools.py        ShapeAnalysis.py     TColQuantity.py
AppParCurves.py          _BRepTopAdaptor.so  GeomAPI.py            _IntTools.so       _ShapeAnalysis.so    _TColQuantity.so
_AppParCurves.so         BSplCLib.py         _GeomAPI.so           IntWalk.py         ShapeBuild.py        TColStd.py
ApproxInt.py             _BSplCLib.so        GeomConvert.py        _IntWalk.so        _ShapeBuild.so       _TColStd.so
_ApproxInt.so            BSplSLib.py         _GeomConvert.so       Law.py             ShapeConstruct.py    TDataStd.py
Approx.py                _BSplSLib.so        GeomFill.py           _Law.so            _ShapeConstruct.so   _TDataStd.so
_Approx.so               CDF.py              _GeomFill.so          LICENSE            ShapeCustom.py       TDataXtd.py
AppStdL.py               _CDF.so             GeomInt.py            LocalAnalysis.py   _ShapeCustom.so      _TDataXtd.so
_AppStdL.so              CDM.py              _GeomInt.so           _LocalAnalysis.so  ShapeExtend.py       TDF.py
AppStd.py                _CDM.so             GeomLib.py            LocOpe.py          _ShapeExtend.so      _TDF.so
_AppStd.so               ChFi2d.py           _GeomLib.so           _LocOpe.so         ShapeFix.py          TDocStd.py
Aspect.py                _ChFi2d.so          GeomLProp.py          LProp3d.py         _ShapeFix.so         _TDocStd.so
_Aspect.so               ChFi3d.py           _GeomLProp.so         _LProp3d.so        ShapeProcessAPI.py   TFunction.py
AUTHORS                  _ChFi3d.so          GeomPlate.py          LProp.py           _ShapeProcessAPI.so  _TFunction.so
Bisector.py              ChFiDS.py           _GeomPlate.so         _LProp.so          ShapeProcess.py      TNaming.py
_Bisector.so             _ChFiDS.so          GeomProjLib.py        MAT2d.py           _ShapeProcess.so     _TNaming.so
BiTgte.py                ChFiKPart.py        _GeomProjLib.so       _MAT2d.so          ShapeUpgrade.py      TopAbs.py
_BiTgte.so               _ChFiKPart.so       Geom.py               Materials.py       _ShapeUpgrade.so     _TopAbs.so
BlendFunc.py             Contap.py           _Geom.so              _Materials.so      SMDSAbs.py           TopBas.py
_BlendFunc.so            _Contap.so          GeomTools.py          math.py            _SMDSAbs.so          _TopBas.so
Blend.py                 Convert.py          _GeomTools.so         _math.so           SMDS.py              TopClass.py
_Blend.so                _Convert.so         GeomToStep.py         MAT.py             _SMDS.so             _TopClass.so
BndLib.py                CPnts.py            _GeomToStep.so        _MAT.so            SMESHDS.py           TopCnx.py
_BndLib.so               _CPnts.so           gp.py                 MeshVS.py          _SMESHDS.so          _TopCnx.so
Bnd.py                   CSLib.py            GProp.py              _MeshVS.so         SMESH.py             TopExp.py
_Bnd.so                  _CSLib.so           _GProp.so             Message.py         _SMESH.so            _TopExp.so
BOPAlgo.py               Dico.py             _gp.so                _Message.so        SortTools.py         TopLoc.py
_BOPAlgo.so              _Dico.so            GraphDS.py            MMgt.py            _SortTools.so        _TopLoc.so
BOPCol.py                Display             _GraphDS.so           _MMgt.so           Standard.py          TopoDS.py
_BOPCol.so               Draft.py            Graphic3d.py          NCollection.py     _Standard.so         _TopoDS.so
BOPDS.py                 _Draft.so           _Graphic3d.so         _NCollection.so    StdFail.py           TopoDSToStep.py
_BOPDS.so                DsgPrs.py           GraphTools.py         NIS.py             _StdFail.so          _TopoDSToStep.so
BOPInt.py                _DsgPrs.so          _GraphTools.so        _NIS.so            StdMeshers.py        TopOpeBRepBuild.py
_BOPInt.so               Dynamic.py          HatchGen.py           NLPlate.py         _StdMeshers.so       _TopOpeBRepBuild.so
BOPTools.py              _Dynamic.so         _HatchGen.so          _NLPlate.so        StdPrs.py            TopOpeBRepDS.py
_BOPTools.so             ElCLib.py           Hatch.py              OSD.py             _StdPrs.so           _TopOpeBRepDS.so
BRepAdaptor.py           _ElCLib.so          _Hatch.so             _OSD.so            StdSelect.py         TopOpeBRep.py
_BRepAdaptor.so          ElSLib.py           Hermit.py             PCDM.py            _StdSelect.so        _TopOpeBRep.so
BRepAlgoAPI.py           _ElSLib.so          _Hermit.so            _PCDM.so           StepAP203.py         TopOpeBRepTool.py
_BRepAlgoAPI.so          ExprIntrp.py        HLRAlgo.py            Plate.py           _StepAP203.so        _TopOpeBRepTool.so
BRepAlgo.py              _ExprIntrp.so       _HLRAlgo.so           _Plate.so          StepAP209.py         TopTools.py
_BRepAlgo.so             Expr.py             HLRAppli.py           PLib.py            _StepAP209.so        _TopTools.so
BRepApprox.py            _Expr.so            _HLRAppli.so          _PLib.so           StepAP214.py         TopTrans.py
_BRepApprox.so           Extrema.py          HLRBRep.py            Plugin.py          _StepAP214.so        _TopTrans.so
BRepBlend.py             _Extrema.so         _HLRBRep.so           _Plugin.so         StepBasic.py         TPrsStd.py
_BRepBlend.so            FairCurve.py        HLRTopoBRep.py        Poly.py            _StepBasic.so        _TPrsStd.so
BRepBndLib.py            _FairCurve.so       _HLRTopoBRep.so       _Poly.so           STEPCAFControl.py    TShort.py
_BRepBndLib.so           FEmTool.py          IFSelect.py           Precision.py       _STEPCAFControl.so   _TShort.so
BRepBuilderAPI.py        _FEmTool.so         _IFSelect.so          _Precision.so      STEPConstruct.py     UnitsAPI.py
_BRepBuilderAPI.so       FilletSurf.py       IGESCAFControl.py     Primitives.py      _STEPConstruct.so    _UnitsAPI.so
BRepCheck.py             _FilletSurf.so      _IGESCAFControl.so    _Primitives.so     STEPControl.py       Units.py
_BRepCheck.so            FSD.py              IGESControl.py        ProjLib.py         _STEPControl.so      _Units.so
BRepClass3d.py           _FSD.so             _IGESControl.so       _ProjLib.so        StepDimTol.py        UTL.py
_BRepClass3d.so          GccAna.py           Image.py              Prs3d.py           _StepDimTol.so       _UTL.so
BRepClass.py             _GccAna.so          _Image.so             _Prs3d.so          STEPEdit.py          V3d.py
_BRepClass.so            GccEnt.py           IncludeLibrary.py     PrsMgr.py          _STEPEdit.so         _V3d.so
BRepExtrema.py           _GccEnt.so          _IncludeLibrary.so    _PrsMgr.so         StepElement.py       Visual3d.py
_BRepExtrema.so          GccGeo.py           __init__.py           __pycache__        _StepElement.so      _Visual3d.so
BRepFeat.py              _GccGeo.so          IntAna2d.py           Quantity.py        StepFEA.py           Visualization.py
_BRepFeat.so             GccInt.py           _IntAna2d.so          _Quantity.so       _StepFEA.so          _Visualization.so
BRepFilletAPI.py         _GccInt.so          IntAna.py             Resource.py        StepGeom.py          Voxel.py
_BRepFilletAPI.so        GccIter.py          _IntAna.so            _Resource.so       _StepGeom.so         _Voxel.so
BRepFill.py              _GccIter.so         IntCurve.py           RWStepAP203.py     StepRepr.py          XBRepMesh.py
_BRepFill.so             GCE2d.py            IntCurvesFace.py      _RWStepAP203.so    _StepRepr.so         _XBRepMesh.so
BRepGProp.py             _GCE2d.so           _IntCurvesFace.so     RWStepAP214.py     STEPSelections.py    XCAFApp.py
_BRepGProp.so            gce.py              _IntCurve.so          _RWStepAP214.so    _STEPSelections.so   _XCAFApp.so
BRepIntCurveSurface.py   _gce.so             IntCurveSurface.py    RWStepBasic.py     StepShape.py         XCAFDoc.py
_BRepIntCurveSurface.so  GCPnts.py           _IntCurveSurface.so   _RWStepBasic.so    _StepShape.so        _XCAFDoc.so
BRepLib.py               _GCPnts.so          InterfaceGraphic.py   RWStepDimTol.py    StepToGeom.py        XCAFPrs.py
_BRepLib.so              GC.py               _InterfaceGraphic.so  _RWStepDimTol.so   _StepToGeom.so       _XCAFPrs.so
BRepLProp.py             _GC.so              Interface.py          RWStepElement.py   StepToTopoDS.py      XSControl.py
_BRepLProp.so            Geom2dAdaptor.py    _Interface.so         _RWStepElement.so  _StepToTopoDS.so     _XSControl.so
BRepMAT2d.py             _Geom2dAdaptor.so   Intf.py               RWStepFEA.py       StepVisual.py
_BRepMAT2d.so            Geom2dAPI.py        _Intf.so              _RWStepFEA.so      _StepVisual.so
BRepMesh.py              _Geom2dAPI.so       IntImpParGen.py       RWStepGeom.py      StlAPI.py

I did the above trouble shooting out of the habit but I think I will use solid-python and openscad combination for the time being;they are sufficient for 3d printing small parts and easy to set up the env.

Thanks for you great work tpaviot.
Not for me right now but a cad library for python seems like a hard-to-write yet very important addition to the language.

Abhinav-Anil commented 4 years ago

I'm using Python = 3.7 PythonOCC = 0.18 Anaconda = 4.8.2

Traceback (most recent call last): File "occutils_geomplate.py", line 37, in from OCC.GeomPlate import (GeomPlate_MakeApprox, ModuleNotFoundError: No module named 'OCC.GeomPlate'

Please help and guide.