1

I use virtualenvwrapper to manage my Python environments. My global postactivate file — a Bash script that gets sourced, after a virtual environment is activated — contains the following:

if [ -f 'activate.sh' ]; then
  echo 'activate virtualenv settings'
  source 'activate.sh'
fi

This should source the activate.sh file only if the project that is connected to the virtual environment contains such a file. But if I use the workon command on a project that contains such a file, I get the following output and error:

activate virtualenv settings
/home/…/.virtualenvs/postactivate: Zeile 15: source: activate.sh: Datei nicht gefunden.

So, the test seems to find the activate.sh file but line 15 throws an error (that's the line with source activate.sh and the error translates to file not found). Why?

3

When in POSIX conformance mode (like when called as sh or when POSIXLY_CORRECT is in the environment), when the argument to source doesn't contain any slash character, bash looks for it in $PATH like POSIX requires for the . utility (the standard equivalent of bash's source) not the current directory.

If it's a sh script you should:

  1. Use ., not source which is not sh/standard.
  2. Use . ./file, if you mean to source the file in the current directory, not . file which would source the first file found in a $PATH lookup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.