Search code examples
pythonubuntuubuntu-20.04pythonpath

Ubuntu Virtualbox: PYTHONPATH gone after restart


I use ubuntu 20.04 on virtualbox and set the python path with the given command

export PYTHONPATH="/path/to/local/folder/"

where my source files for modules I want to load are located. But everytime I reboot the VM, the python path is reset, echo $PYTHONPATH does not return anything. I hope someone could help me with this issue as I'm really new to ubuntu.

Edit: I work in a conda virtual environment and want to set the path there


Solution

  • This is more a ServerFault question than a StackOverflow question, but regardless..

    To declare a permanent environment variable, do one of the following:

    • Set it for just you and your sessions in your bash profile with echo 'export PYTHONPATH="/path/to/local/folder/"' >> ~/.profile
    • Set it system-wide in profile.d with echo 'export PYTHONPATH="/path/to/local/folder"' >> /etc/profile.d/pythonpath.sh && chmod 755 /etc/profile.d/pythonpath.sh

    For the second one you'll need sudo/root permissions, and it will take effect for all users on the host. Just depends on how you want to do it and how you want things to work.

    EDIT: Including reference material as well: https://help.ubuntu.com/community/EnvironmentVariables