Incude FreeCAD in system path for just one conda virtual environment
Asked Answered
P

2

1

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.

Palindrome answered 18/8, 2019 at 8:34 Comment(0)
A
1

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.

Alsacelorraine answered 18/8, 2019 at 8:47 Comment(3)
Thanks! It looks like FreeCAD does not support being pip or conda installed because they want to use a python installation internal to the program.Palindrome
Create a symbolic link in $HOME/path/to/anaconda/lib/pythonX.X/site-packages should be the easiest solution.Alsacelorraine
Maybe so. I used "conda develop /usr/lib/freecad-python3/lib/", and it worked.Palindrome
E
0

You might go to the virtualenv site packages dir and add the path to the freecad into easy_install.pth

Engender answered 18/8, 2019 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.