permanet setting of pathes to extern modules

Need help, or want to share a macro? Post here!
User avatar
microelly2
Posts: 4256
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

permanet setting of pathes to extern modules

Postby microelly2 » Sun Apr 23, 2017 10:58 am

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
Posts: 2555
Joined: Wed May 16, 2012 2:13 pm

Re: permanet setting of pathes to extern modules

Postby mario52 » Sun Apr 23, 2017 11:38 am

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, Dialog creation. My macros on Gist.github.
looo
Posts: 2559
Joined: Mon Nov 11, 2013 5:29 pm

Re: permanet setting of pathes to extern modules

Postby looo » Sun Apr 23, 2017 12:42 pm

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
Posts: 4256
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: permanet setting of pathes to extern modules

Postby microelly2 » Sun Apr 23, 2017 6:15 pm

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.
looo
Posts: 2559
Joined: Mon Nov 11, 2013 5:29 pm

Re: permanet setting of pathes to extern modules

Postby looo » Mon Apr 24, 2017 3:03 pm

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

Re: permanet setting of pathes to extern modules

Postby crobar » Fri Apr 28, 2017 8:15 pm

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.