pipuv

How to add --install-option key and value in uv like in pip


I'm using uv as my Python package manager, and I have the following command to install a package with pip:

$ pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" \ 
--install-option="--library-path=/usr/lib/graphviz"

My uv version is 0.6.14, and Python version is 3.10.

How can I achieve the same installation in uv?


What I have tried

  1. uv add package

    $ uv add pygraphviz
    

    Output

    × Failed to build `pygraphviz==1.14`
    ├─▶ The build backend returned an error
    ╰─▶ Call to `setuptools.build_meta.build_wheel` failed (exit    status: 1)
    
      [stdout]
      running bdist_wheel
      running build
      running build_py
      ...
      gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -  fPIC -DSWIG_PYTHON_STRICT_BYTE_CHAR -I/root/.cache/uv/builds-  v0/.tmpgLYPe0/include -I/usr/local/include/python3.12 -c  pygraphviz/graphviz_wrap.c -o
      build/temp.linux-x86_64-cpython-312/pygraphviz/graphviz_wrap.o
    
      [stderr]
      ...
      pygraphviz/graphviz_wrap.c:9: warning:   "SWIG_PYTHON_STRICT_BYTE_CHAR" redefined
          9 | #define SWIG_PYTHON_STRICT_BYTE_CHAR
            |
      <command-line>: note: this is the location of the previous definition
       pygraphviz/graphviz_wrap.c:3023:10: fatal error: graphviz/cgraph.h: No such file or directory
        3023 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
    
      hint: This error likely indicates that you need to install a  library that provides "graphviz/cgraph.h" for `[email protected]`
    

    The post suggests installing libgraphviz-dev system-wide, but this is not an option for me due to permission restrictions. That’s why I need to know how to specify the library path, so I can place the necessary files in a directory where I have access.

  2. uv compatible pip command

    $ uv pip install pygraphviz --install-option="--include-path=/myfolder/include/graphviz" \ 
    --install-option="--library-path=/myfolder/lib/graphviz"
    

    Output

    Output:
    
    error: unexpected argument '--install-option' found
    
      tip: a similar argument exists: '--reinstall'
    
    Usage: uv pip install --reinstall <PACKAGE|--requirements <REQUIREMENTS>|--editable <EDITABLE>|--group <GROUP>>
    
    For more information, try '--help'.
    

Solution

  • I think this do the trick:

    CFLAGS="-I/myfolder/include/graphviz" LDFLAGS="-L/myfolder/lib/graphviz" uv pip install pygraphviz
    

    CFLAGS stands for C Compiler Flags.-I/myfolder/include/graphviz tells the compiler for header files (.h).

    LDFLAGS stands for Linker Flags. -L/myfolder/lib/graphviz tells the linker for libraries (.so).