So I've been thinking, it'd be nice to have the ability to specify additional paths from within FreeCAD to append to it's Python virtual environment. I realize it's probably a bit superfluous for the average dev, but I can see use cases where it might come in handy - for example, being able to specify python libraries for testing purposes (just a one-off test to add / remove), as well as a convenient way to see and edit what's currently in the environment.
Even something as horribly clunky as Window's environment variable editor would be nice to have, here.
Feature Request: Python virtual env variable editing
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Feature Request: Python virtual env variable editing
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
-
- Posts: 656
- Joined: Tue May 19, 2015 1:11 am
Re: Feature Request: Python virtual env variable editing
Does something like this not get the job done?
Code: Select all
import sys
sys.path.insert(0, “/my/custom/lib/location”)
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Feature Request: Python virtual env variable editing
It does, but I'm already doing that with macros that I run every time I run FreeCAD. And it's fine.
But... wouldn't it be nice to be able to see exactly what's in the environment? and not just as a text string dumped to the console?
Really, in my mind, the virtual environment is a big enough part of FreeCAD it deserves a little UI love.
But... wouldn't it be nice to be able to see exactly what's in the environment? and not just as a text string dumped to the console?
Really, in my mind, the virtual environment is a big enough part of FreeCAD it deserves a little UI love.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Feature Request: Python virtual env variable editing
If I get your idea right, what you want is similar to Spyder's "PYTHONPATH manager". Basically adding paths to PYTHONPATH is the easiest way to get more directories into your environment from which to import modules.Joel_graff wrote: ↑Tue Sep 10, 2019 5:21 pm ...
But... wouldn't it be nice to be able to see exactly what's in the environment? and not just as a text string dumped to the console?
...
In the terminal it would be
Code: Select all
PYTHONPATH=/usr/lib/freecad/Mod FreecAD
The Spyder source code is MIT licensed, which is pretty compatible with the LGPL 2 of FreeCAD. So we could just copy its code and modify it to our needs without much problem.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Feature Request: Python virtual env variable editing
That looks like a good starting point. If nothing else, just a manager for python path changes made by the user. Sort of like a user-level list of paths applied after the system level paths.
Obviously, it'd be nice to be able to see everything and manage the entire path, but that might be more trouble than it's worth, lol
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Feature Request: Python virtual env variable editing
Yes, I'm not really sure about you have in mind, but allowing the user to modify the system path sounds kinda wild. In my mind, this is the better approach, adding to their user path, on top of the system one.Joel_graff wrote: ↑Tue Sep 10, 2019 5:41 pm ...
Obviously, it'd be nice to be able to see everything and manage the entire path, but that might be more trouble than it's worth, lol
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Feature Request: Python virtual env variable editing
Right... I think the system-level information might be useful, at least as read-only, but really, I only had in mind to use it to manage one-off libraries that aren't installed in the system paths - maybe just testing a new library or something. Anyway, having something that persists across FreeCAD sessions without having to specify a command line parameter, write a macro, or add it in the console would be nice.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Feature Request: Python virtual env variable editing
That would be the parameter database, that just adds the respective parameter to the user.cfg file. So the Spyder-based widget would justJoel_graff wrote: ↑Tue Sep 10, 2019 5:52 pm ... Anyway, having something that persists across FreeCAD sessions without having to specify a command line parameter, write a macro, or add it in the console would be nice.
Code: Select all
ParamGet("User preferences").GetParam("PYTHONPATH") to add additional directories.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Feature Request: Python virtual env variable editing
Using sys.path.append() makes the path immediately available, so I would be a little concerned if using Spyder required restarting FreeCAD...
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers