Thanks, this is quite interesting -- my one concern is the last bit: this way it does not persist between restarts of FreeCAD, right? So really I have to have FreeCAD's core startup code know about the new location we are creating, right?onekk wrote: ↑Fri Jan 07, 2022 3:40 pmCode: Select all
MODULE_PATH = packages_dir if MODULE_PATH not in sys.path: sys.path.insert(-1, MODULE_PATH)
Running pip from within FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Running pip from within FreeCAD
Re: Running pip from within FreeCAD
@wmayer what do you think about this strategy?
- We maintain a simple (no-version information) list of allowed Python packages: any requirements.txt entry that doesn't have an entry gets removed and is not installed. This only applies to actual entries in the requirements.txt file, not to any dependencies those bring in.
- All python packages are installed in $USER_APP_DATA_DIR/PythonPackages (or some other suitable name). We add this path to the end of FreeCAD's standard Python path (e.g. so a later-installed system package would override, etc.).
- Addon Manager has a preference for the Python executable to use, and if not set, searches as described by @onekk above. This seems to be the most conservative approach: if we can't figure out the exact right executable, don't guess, don't install.
Re: Running pip from within FreeCAD
It is not persistent as AppImage have no an autoload mechanism. But maybe using the autoloading mechanism of user\Mod dir something could be achieved.
But as you install packages as dependencies of AddOns, maybe it is the plugin itselt that could had the "pip user dir" to the path if not already present or the AddOn Manager itself could have these lines in it.
Main concern could be the fact that installed packages are not showing in "pip list" but this could even an advantage to mantain a better isolation from the system.
Do you have seen pipx as it claims that it is able to mantain isolation and control over what is installed.
It is cited in Python official documentation so it should not be too bad.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Running pip from within FreeCAD
OK, I have a PR in that implements this strategy -- thanks to everyone for your assistance in making this happen. Now I need help testing it! Some of the tests I don't know how to do, because we don't really have a way to easily package up the PR as a flatpack, Docker image, Snap, etc. I'm open to testing suggestions on those fronts, if you have ideas.
Re: Running pip from within FreeCAD
For the initial allowed list of Python packages, I've got:
That covers all of the packages that are currently specified in metadata files in "official" addons. I would guess there are also dependencies out there that are not yet set in a metadata file, but I have no way of knowing what those are. Any objections to this initial list? Any obvious additions I should make?
Code: Select all
ezdxf
markdown
numpy
olefile
pillow
pygit2
requests
scipy
xlrd
xlutils
xlwt
PyYAML
Re: Running pip from within FreeCAD
Here is my wishlist :
- pandas (https://pypi.org/project/pandas)
pynastran (https://pypi.org/project/pyNastran/)
openpyxl (https://pypi.org/project/openpyxl/)
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Running pip from within FreeCAD
I think scipy and numpy are already included. I don't recall installing them separately and I am able to import both in the python console without error.
- ebrahim raeyat
- Posts: 619
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: Running pip from within FreeCAD
and for mine:nic wrote: ↑Fri Jan 14, 2022 7:03 pm Here is my wishlist :
- pandas (https://pypi.org/project/pandas)
pynastran (https://pypi.org/project/pyNastran/)
openpyxl (https://pypi.org/project/openpyxl/)
- pandas
openpyxl : for export to .xlsx format
python-docx : for creating reports in .docx format
comtypes: for communicating with windows software
Re: Running pip from within FreeCAD
Which workbench are you using these in? Can you add them to a requirements.txt file when you have a moment?nic wrote: ↑Fri Jan 14, 2022 7:03 pm Here is my wishlist :
- pandas (https://pypi.org/project/pandas)
pynastran (https://pypi.org/project/pyNastran/)
openpyxl (https://pypi.org/project/openpyxl/)