How can we compute the ratio between the distributions if we don't know one of the distributions?
The rationale behind importance sampling is that $q(x)$ is difficult to sample from but easy to evaluate. Or at least you can easily evaluate some $\tilde{q}$ such that:
$$
\tilde{q}(z) = Zq(z)
$$
where $Z$ (scalar) might be unknown. The geometrical example would be here e.g. sampling uniformly from an area under the curve $q(x)$ (in general it's not easy).


  Because if we know $q(x)$, then we can compute the expectation directly.


That's the task we're trying to solve to begin with. And calculating expectation might be hard if we can't sample efficiently from $q$. 

Say you want to compute an expectation of $x$, $E[x]$. For this you need to calculate the following integral:
$$
E[x] = \int{xq(x)dx}
$$
where $q$ is a probability distribution of $x$ for which you have an expression - so you can evaluate $q(x)$ (up to the constant of proportionality). This integral might be hard to evaluate analytically so we need to use other methods such as Monte Carlo. Let's say it is hard to generate samples from $q$ (as per example above, e.g. generating samples from the area under the curve $q(x)$ uniformly). 

What you can do is to calculate an expectation under a simple distribution $p$ (proposal distribution) which is a distribution of your choice that needs to allow you to easily sample from it (say Gaussian). Then you can rewrite your integral as:
$$
E_q[x] = \int{xq(x)dx} = \int{xq(x) \color{blue}{\frac{p(x)}{p(x)}} dx}
= \int{x \frac{q(x)}{\color{blue}{p(x)}} \color{blue}{p(x)} dx}
= E_p \Big[{x\frac{q(x)}{p(x)}}\Big]
$$
(added index $p$ and $q$ to expectation to denote the sampling distribution). Now you can approximate the last expectation by Monte Carlo:
$$
E_p \Big[{x\frac{q(x)}{p(x)}}\Big] = \frac{1}{S} \sum_{s}{x^{(s)} \frac{q(x^{(s)})}{p(x^{(s)})} }, \ x^{(s)} \sim q(x)
$$