I have test code that wants to require some utility code in the same directory. I would prefer to not update the load-path, as most of the time, I do not want me or any other user who has checked out this code to be looking in this directory.

It seemed that (require 'utils "./utils.el") should work, but this gives me an error:

file-remote-p: Cannot open load file: No such file or directory, ./utils.el

Is there a better way than something like

(let ((load-path (append (list (file-name-directory (buffer-file-name))))
    (require 'utils))

I also cannot specify an absolute path, as the path may be different when other users check out the repository.

  • 1
    Have you tried expand-file-name?
    – npostavs
    Commented Apr 26, 2017 at 19:49
  • 1
    You could also try load-file instead. Commented Apr 26, 2017 at 23:04

1 Answer 1


Like John Kitchin pointed out, load-file does what you want. For example:

(setq my-utils-file "utils.el")
  (expand-file-name my-utils-file
                    (file-name-directory (buffer-file-name))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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