Question: I'm a little confused about the scope of `require`s and `import`s in Clojure. Can I somehow require dependencies that only stay in scope within a function?

When I do something like the following, I get the shown error.

```
user=> (defn test1 [x] (require '[taoensso.timbre :as timbre]) (timbre/log x))

CompilerException java.lang.RuntimeException: No such namespace: timbre, compiling:(/tmp/form-init1203922056301029971.clj:1:57) 

```

Answer: 
I'm not sure of your motivation for moving the `require` statements out of the `ns` declarations. The `require` statements state the dependencies of that namespace. 

If these dependencies only relate to certain functions of the namespace, you might consider moving those functions into a different namespace, thereby freeing the first namespace of dependencies, and creating looser coupling.
I don't disagree with Grav's suggestion--that is an option--but I don't see much of a drawback to loading a dependency for use only with one function.

Occasionally there is a reason to temporarily switch namespaces within a file using either `ns` or `in-ns`:

```
(ns foo.bar)

... more code here ...

(ns foo.parameters [:require foo.baz :as bz])
(def my-parm (bz/inc2 42))
(ns foo.bar)

```

You could use this to make a `require`d namespace available only temporarily, but this is something that usually should be avoided.

Like many people, [Colin Jones' blog post](https://8thlight.com/blog/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html) is my favorite introduction to namespaces.