[Python] libtorch and pytorch cannot be installed simultaneously?

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I am learning to develop with PyTorch as well as LibTorch. I have the following line in my ~/.bashrc for dynamic linking of libtorch libraries:

    # libtorch linking path
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/.dev_libraries/libtorch/lib/


    However, when this path is in LD_LIBRARY_PATH, importing torch in Python reports segmentation fault:

    user@host:~$ $LD_LIBRARY_PATH
    bash: /home/user/packages/embree-2.16.0.x86_64.linux/lib:/home/user/packages/embree-2.16.0.x86_64.linux/lib::/usr/local/lib/:/usr/local/cuda-11.1/lib64:/usr/local/lib/:/usr/local/cuda-11.1/lib64:/home/user/.dev_libraries/libtorch-cpu/libtorch/lib/: No such file or directory
    user@host:~$ python
    Python 3.8.10 (default, Jun 2 2021, 10:49:15)
    [GCC 9.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import torch
    Segmentation fault (core dumped)
    user@host:~$


    As soon as I remove that path from the environment variable LD_LIBRARY_PATH, torch can be correctly imported in Python.

    I am guessing the cause is that some shared libraries of PyTorch having the same names as the ones in LibTorch. Does this mean PyTorch and LibTorch cannot be installed simultaneously, or is my environment setting incorrect? I'd prefer not to reset LD_LIBRARY_PATH every time I switch between the two.


    System specs:


    Continue reading...

Compartilhe esta Página