The rational design of novel molecules with desired bioactivity is a critical but challenging task in drug discovery, especially when treating a novel target family or understudied targets. Here, we propose PGMG, a pharmacophore-guided deep learning approach for bioactivate molecule generation. Through the guidance of pharmacophore, PGMG provides a flexible strategy to generate bioactive molecules matching given pharmacophore models. PGMG uses a graph neural network to encode pharmacophore features and spatial information and a transformer decoder to generate molecules. A latent variable is introduced to solve the many-to-many mapping between pharmacophores and molecules and improve the diversity of generated molecules. In addition, these generated molecules are of high validity, uniqueness, and novelty. In the case studies, we demonstrate using PGMG in ligand-based and structure-based drug de novo design, as well as in lead optimization scenarios. Overall, the flexibility and effectiveness make PGMG a useful tool to accelerate drug discovery process.