仅在一个 conda 虚拟环境的系统路径中包含 FreeCAD [英] Incude FreeCAD in system path for just one conda virtual environment

查看:93
本文介绍了仅在一个 conda 虚拟环境的系统路径中包含 FreeCAD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将 FreeCAD 导入到我的 python 脚本中,但只能在一个 conda 虚拟环境中.有没有办法在不将 FreeCAD 添加到每个文件开头的路径的情况下做到这一点?我正在使用 Pop!_OS,这里的行为应该像 Ubuntu.

I want to be able to import FreeCAD into my python scripts, but only in one conda virtual environment. Is there a way to do this without adding FreeCAD to the path at the beginning of each file? I am using Pop!_OS, which should behave like Ubuntu here.

我已经发现您可以导入 FreeCAD,但我找到的源代码是通过在文件开头附加 FreeCAD 库位置来实现的:https://www.freecadweb.org/wiki/Embedding_FreeCAD.看起来你可以通过修改你的路径变量来规避这个问题,我能够在我工作场所的 Windows 上这样做.我只想为特定的 conda 虚拟环境执行此操作.

I already found that you can import FreeCAD, but the source I found did so by appending the FreeCAD library location at the beginning of the file: https://www.freecadweb.org/wiki/Embedding_FreeCAD. It looks like you could circumvent this problem by modifying your path variable, and I was able to do so on Windows in my workplace. I just want to do this only for a particular conda virtual environment.

理想情况下,

import FreeCAD

将在特殊的虚拟环境中工作,但不能在其他环境中工作.

will work in a special virtual environment, but not in others.

如前所述,通过将 FreeCAD 的目录添加到 PATH 环境变量,我已经让 import 语句在 Windows 上工作.它与命令提示符下的默认 python 一起工作,这应该是 anaconda 安装,所以我认为它适用于所有虚拟环境.但是,在 Linux 上,即使我使用了,我也无法在 python 中导入 FreeCAD

As mentioned, I got the import statement to work on Windows already by adding FreeCAD's directory to the PATH environment variable. It worked with the default python in command prompt, which should be the anaconda installation, so I think it works in all virtual environments. On Linux, though, I cannot import FreeCAD in python even when I use

PATH=$PATH:/usr/lib/freecad-python3/lib/

这是我从 "locate FreeCAD.so" 得到的.我得到

which I got from "locate FreeCAD.so" . I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'FreeCAD'

如果能够在两个操作系统上运行相同的代码,并且将 PATH 修改限制在一个虚拟环境中,那就太好了.

It would be really nice to be able to run the same code on both operating systems, and have the PATH modification confined to one virtual environment.

推荐答案

Conda 不会从 PATH 环境中查找包.查看此答案了解详情.但首先检查您的软件包是否可以使用 pipconda 安装.

Conda does not look for packages from the PATH environment. Check this answer for the details. But first check whether your package can be installed using pip or conda.

这篇关于仅在一个 conda 虚拟环境的系统路径中包含 FreeCAD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆