1

I need some help with appending a file path to "PATH" variable in Windows 10 from Jupyter Notebook (Python 3.6). I need to do it at run time from notebook because my user account is doesn't have admin rights.

Background:

I want to use GrphViz 2.8 library. For this library to work from Jupyter notebook, the location of dot.exe file i.e. C:\Program Files (x86)\Graphviz2.38\bin\dot.exe needs to be added to PATH environment variable.

I have seen that os.getenv('Path') command will get me the value of this Path variable but I couldn't find the equivalent set method to append my entry to this Path variable.

I have also seen this post which suggests using kernal.json But I didn't understand how to update the PATH variable.

Any example how to achieve this will be very much appreciated.

If it is not possible, then can you please suggest an alternative way of using GrpahViz without updating "Path" variable.

PS I can't use Online dot-file to SVG/PNG converters because I am using a package which requires GrpahViz to be available locally.

Khurram Majeed
  • 2,291
  • 8
  • 37
  • 59
  • 1
    Best would be to add te mentioned path to the PATH variable of your system. Alternatively you could, probably, use `os.putenv` or `os.environ` (see e.g. https://docs.python.org/3/library/os.html) – albert Mar 06 '19 at 13:10

1 Answers1

3

Try this:

import os
os.environ['PATH'] += os.pathsep + r'C:\Program Files (x86)\Graphviz2.38\bin\dot.exe'
Hiadore
  • 686
  • 3
  • 15
  • path with the name of the executable? – albert Mar 06 '19 at 15:13
  • Yes @albert, path to the executable file. – Hiadore Mar 06 '19 at 18:19
  • You write "path to the executable file" but this would, as far as I know, be "C:\Program Files (x86)\Graphviz2.38\bin" – albert Mar 06 '19 at 18:22
  • I think path to executable mean the full path of the file, include filename. Your case is likely more precisely called path to directory of the executable. See http://www.itgeared.com/articles/1059-how-to-change-services-path-to/ – Hiadore Mar 06 '19 at 22:32
  • Why would the executable name be included here? PATH defines directories in which Windows will search for executables. – bugmenot123 Nov 18 '19 at 14:55