通过anacoda安装
1、下载anaconda,界面安装
2、配置环境变量
右键单击我的电脑->属性->高级系统设置->环境变量->系统环境变量->选中Path-点击编辑->将下列内容copy到队尾->确定
D:\Envs\anaconda3;
D:\Envs\anaconda3\Scripts;
D:\Envs\anaconda3\Library\mingw-w64\bin;
D:\Envs\anaconda3\Library\usr\bin;
D:\Envs\anaconda3\Library\bin;
3、通过anaconda创建虚拟环境
conda create --name=pyoccenv python=3.9
#windows下打开Anaconda Prompt运行上述代码
4、激活虚拟环境
#linuxs source activate pyoccenv
#windows下 activate pyoccenv
5、安装PythonOCC
conda install -c conda-forge pythonocc-core=7.5.1
6、安装Pyqt5
pip install pyqt5 -i https://pypi.tuna.tsinghua.edu.cn/simple
7、测试
from OCC.Display.SimpleGui import init_display
from OCC.Extend.DataExchange import read_iges_file,read_step_file,read_stl_file
if __name__ == '__main__':
shapes=read_step_file("1.stp")
# shapes=read_stl_file("1.stp")
#shapes=read_iges_file("1.stp")
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(shapes, update=True)
start_display()
8、(option)如果报错meaningless REX prefix used
#不知道为什么,但可以简单解决
#打开运行环境文件F:\anaconda3\envs\pyocc\lib\site-packages\OCC\Display\qtDisplay.py
#将38行内容从:
class qtBaseViewer(QtOpenGL.QGLWidget):
#替换成
class qtBaseViewer(QtWidgets.QWidget):