Forums

PATH not marked for export

I had this issue where none of my custom tools were available in Bash, and tracing it back, I put declare -p PATH at the top of my ~/.profile, which says this:

declare -- PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Which indicates that PATH isn't marked for export, otherwise it would say declare -x ...

Now, I just checked on my desktop Ubuntu 18.04 install and saw that PATH is marked for export before running ~/.profile, which seems to indicate that this is a configuration issue on PythonAnywhere, is that right?

What do you mean by custom tools and what kind of issues did you get? Default .profile on PythonAnywhere is set to source ~/.bashrc which exports the PATH. If you need to add something to the PATH, you can edit ~/.bashrc.

As a workaround, I put this line at the top of my ~/.profile:

export PATH

@pafk, I mean I have some executables in directories that are added to the PATH in ~/.profile, but because the PATH wasn't exported, the changes didn't take effect, so the executables just weren't available to run. For example, I have autopep8 in ~/.local/bin/, but trying to run it errored bash: autopep8: command not found.

.bashrc is actually not the best place to put environment variables, cause it'll only affect Bash. Instead, .profile will affect other programs like IPython for example. For reference, see the Ubuntu wiki: Session-wide environment variables. And for an example, /etc/skel/.profile contains these lines:

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"

Also I forgot to mention, this issue wasn't occurring before, though I don't know when it started cause I haven't been on PythonAnywhere very much in the past year.

On PythonAnywhere .profile is sourcing .bashrc explicitly so it is not bash-only in our case.

@fjl Are you sure? I've customized mine, but looking at /etc/skel/.profile, it only sources ~/.bashrc if running Bash:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

@fjl On second thought, why would you even have that setup? If you run dash for example, won't it choke on Bash-specific stuff?

You can customize it, but the default is as I described above.