简体   繁体   English

将 FreeCAD 导入 Python 以在外部脚本中使用

[英]Import FreeCAD to Python to use in external Script

I am currently working on a Projekt to get data from FreeCAD to use in an external script.我目前正在使用 Projekt 从 FreeCAD 获取数据以在外部脚本中使用。

My FreeCAD installation:我的 FreeCAD 安装:

OS: Windows 10 Word size of OS: 64-bit Word size of FreeCAD: 64-bit Version: 0.18.4 (GitTag) Build type: Release Branch: releases/FreeCAD-0-18 Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8 Python version: 3.6.6 Qt version: 5.6.2 Coin version: 4.0.0a OCC version: 7.3.0 Locale: German/Germany (de_DE)

And have problems to import this to a python script.并且在将其导入 python 脚本时遇到问题。

I am using Python 3.7.4我正在使用 Python 3.7.4

My Source code:我的源代码:

import sys

# Path to FreeCAD
FREECADPATH = 'C:\FreeCAD 0.18\bin'

def import_freecad(path_freecad):
    """Try to import FreeCAD on path_freecad"""
    sys.path.append(path_freecad)
    try:
        import FreeCAD
    except:
        print("Could not import FreeCAD")

import_freecad(FREECADPATH)

This code always raises the expection.这段代码总是让人期待。 I followed a tutorial pdf you easily can find when google for it.我遵循了一个教程 pdf,你很容易在谷歌上找到它。

Anyone has an idea on how to solve this?任何人都知道如何解决这个问题? Or solved the problem themself?还是自己解决了问题?

Have you tried the "anaconda way"?您是否尝试过“蟒蛇方式”? Seems easier.似乎更容易。 You can create your own virtual env.( https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands )您可以创建自己的虚拟环境。( https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands

And then just type in terminal:然后只需输入终端:

conda install -c conda-forge/label/cf201901 freecad

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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