The following was explained to me by Jean-Pierre Ferrier, and Ahmed Jeddi made useful comments.
For any matrix $a$ in $A:=M_n(\mathbb C)$, write $\Lambda(a)$ for the set of eigenvalues of $a$. For each $\lambda$ in $\Lambda(a)$, write $1_\lambda\in\mathbb C[a]$ for the projector onto the $\lambda$-generalized eigenspace parallel to the other generalized eigenspaces, and put $a_\lambda:=a1_\lambda$, and $z_\lambda:=z1_\lambda$ for $z$ in $\mathbb C$.
Let $U$ be an open subset of $\mathbb C$, let $U'$ be the subset of $A$, which is open by Rouché's Theorem, defined by the condition $\Lambda(a)\subset U$, let $a$ be in $U'$, let $X$ be an indeterminate, let $\mathcal O(U)$ be the $\mathbb C$-algebra of holomorphic functions on $U$, and equip $\mathcal O(U)$ and $\mathbb C[a]$ with the $\mathbb C[X]$-algebra structures associated respectively with the element $z\mapsto z$ of $\mathcal O(U)$ and the element $a$ of $\mathbb C[a]$.
Theorem 1. (i) There is a unique $\mathbb C[X]$-algebra morphism from $\mathcal O(U)$ to $\mathbb C[a]$. We denote this morphism by $f\mapsto f(a)$.
(ii) The map $U'\ni a\mapsto f(a)\in A$ is holomorphic.
(iii) For any $a$ in $U'$ we have $ f(a)=\sum_{\lambda\in\Lambda(a),0\le k
Proof of (i) and (iii). By the Chinese Remainder Theorem, $\mathbb C[a]$ is isomorphic to the product of $\mathbb C[X]$-algebras of the form $\mathbb C[X]/(X-\lambda)^m$, with $\lambda\in\mathbb C$. So we can assume that $\mathbb C[a]$ is of this form, and the lemma follows from the fact that, for any $f$ in $\mathcal O(U)$, there is unique $g$ in $\mathcal O(U)$ such that $ f(z)=\sum_{k=0}^{m-1}\ \frac{f^{(k)}(\lambda)}{k!}\ (z-\lambda)^k+(z-\lambda)^mg(z) $ for all $z$ in $U$. q.e.d.
Say that a cycle is a formal finite sum of smooth closed curves. Let $\gamma$ be a cycle in $U\setminus\Lambda(a)$ such that $I(\gamma,\lambda)=1$ for all $\lambda\in\Lambda(a)$ (where $I(\gamma,\lambda)$ is the winding number of $\gamma$ around $\lambda$), and let $N$ be the set of those $b$ in $A$ such that $\Lambda(b)\subset U$, and that $\gamma$ is a cycle in $U\setminus\Lambda(b)$ satisfying $I(\gamma,\lambda)=1$ for all $\lambda\in\Lambda(b)$. As already observed, Rouché's Theorem implies that $N$ is an open neighborhood of $a$ in $A$. Theorem 2 below will imply Part (ii) of Theorem 1.
Theorem 2. We have $ f(b)=\frac{1}{2\pi i}\int_\gamma\ \frac{f(z)}{z-b}\ dz $ for all $f$ in $\mathcal O(U)$ and all $b$ in $N$. In particular the map $b\mapsto f(b)$ from $U'$ to $A$ is holomorphic.
Proof. We have $ \frac{1}{2\pi i}\int_\gamma\ \frac{f(z)}{z-b}\ dz $ $ =\frac{1}{2\pi i}\int_\gamma\ \frac{f(z)}{z-b}\ \sum_{\lambda\in\Lambda(b)}1_\lambda\ dz $ $ =\sum_{\lambda\in\Lambda(b)}\frac{1_\lambda}{2\pi i}\int_\gamma\ \frac{f(z)}{z-b}\ dz $ $ =\sum_{\lambda\in\Lambda(b)}\frac{1_\lambda}{2\pi i}\int_\gamma\ \frac{f(z)\ dz}{(z-\lambda)-(b-\lambda)} $ $ =\sum_{\lambda\in\Lambda(b)}\frac{1_\lambda}{2\pi i}\int_\gamma\ f(z)\ \sum_{k=0}^{n-1}\ \frac{(b-\lambda)^k}{(z-\lambda)^{k+1}}\ dz $ $ =\sum_{\lambda\in\Lambda(b),0\le k $ \overset{(*)}{=}\sum_{\lambda\in\Lambda(b),0\le k $ =\sum_{\lambda\in\Lambda(b),0\le k $ \overset{(**)}{=}f(b), $ where Equality $(*)$ follows from the Residue Theorem, and Equality $(**)$ from Part (iii) of Theorem 1. q.e.d.