简体   繁体   中英

Incude FreeCAD in system path for just one conda virtual environment

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.

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.

Ideally,

import FreeCAD

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

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/

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'

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 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 .

您可以转到virtualenv站点软件包dir并将freecad的路径添加到easy_install.pth中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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