permanet setting of pathes to extern modules

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

permanet setting of pathes to extern modules

Post by microelly2 »

I have installed freecad on windows 7 and cv2

The testcase is running

Code: Select all

import sys
sys.path.append('E:\\opencv\\build\\python\\2.7\\x64')
import cv2

fn='E:\\kscan3d\\4.jpg'

img=cv2.imread(fn)
cv2.imshow(fn,img)


Is there a way to add the path to the python binding of cv2 permanently?

like

FreeCAD.ParamGet(' :?: PYTHON SEARCH PATH :?: ').GetString("#1",'E:\\kscan3d\\4.jpg')


It would be nice to have the opportunity to add more extern modules somewhere in the configuration settings.
Having such a functionality we can install more and different versions (for example for cv2, networkx, ..) and switch between them
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: permanet setting of pathes to extern modules

Post by mario52 »

hi

normally with Windows

Propriétés système > Paramètres Systeme avancé > Variables d'environnement > Variables système Path ( ...... ; my new path)
(sorry french)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: permanet setting of pathes to extern modules

Post by looo »

maybe a user-startup-file would be a good idea? Something like .bashrc or .pythonrc. As a workaround you can use a startupMod (create file: .FreeCAD/Mod/startUp/Init.py and place the sys.path modifications there)

Maybe someone can report the problem with cv2 install-dir to the developers of cv2?
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: permanet setting of pathes to extern modules

Post by microelly2 »

looo wrote:maybe a user-startup-file would be a good idea? Something like .bashrc or .pythonrc. As a workaround you can use a startupMod (create file: .FreeCAD/Mod/startUp/Init.py and place the sys.path modifications there)
This is the idea I will follow, it works for portable installations and can handle multiple versions and 32/64 bit in parallel.
Maybe someone can report the problem with cv2 install-dir to the developers of cv2?
What problem do you think :?:

+mario52 thanks for the tipp but I need a more flexible solution.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: permanet setting of pathes to extern modules

Post by looo »

microelly2 wrote:What problem do you think :?:
cv2 installs the python-bindings to a wrong directory...
crobar
Posts: 160
Joined: Fri Aug 29, 2014 1:26 pm

Re: permanet setting of pathes to extern modules

Post by crobar »

I solved the same problem by creating a new wokbench called Run Startup Script, which you can do by putting the following code in a file in .FreeCAD/Mod/Run_Startup

Code: Select all


class RunStartupWorkbench (Workbench):
    # Icon generated using by converting linearDimension.svg to xpm format using Gimp
    Icon = '''
/* XPM */
static char * linearDimension_xpm[] = {
"32 32 10 1",
"       c None",
".      c #000000",
"+      c #0008FF",
"@      c #0009FF",
"#      c #000AFF",
"$      c #00023D",
"%      c #0008F7",
"&      c #0008EE",
"*      c #000587",
"=      c #000001",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".      +@@             +       .",
".    @+@@+            +@@+@    .",
". +@+@@@@@@          @@@@@@@#  .",
"$%@@@@@@@@@+@@@@@@@@@@@@@@@@@@&$",
". #@@@@@@@@         #+@@@@@@@@*=",
".    @+@@+            +@@@@@   .",
".      +@             #@++     .",
".                      #       .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              .",
".                              ."};
'''
    MenuText = 'Run Startup Script'
    def Initialize(self):
        FreeCADGui.doCommand("execfile('/home/rcrozier/.FreeCAD/startup.FCMacro')")

Gui.addWorkbench(RunStartupWorkbench())
If you then make this the default startup workbench it will run whatever you put in startup.FCMacro referenced toward the end in the python interpreter every time you start FreeCAD.
Post Reply