How to Import All Python Libraries With One Line of Code | by Ismael Araujo | Towards Data Science

If you are a Data Scientist or are learning how to become one, you know the drill when starting a new Jupyter Notebook project. You import libraries, use some of them, and start working. You will likely get an error message at some point because you forgot to import another library. You stop whatever you were working on, import that specific library, and start working again. Depending on the size of your project, this can happen a few times. It’s also highly likely that you have checked on Google how to import matplotlib.plot.
Yes, you can make your life easier and copy and paste all the packages you will need from another project, but what if I tell you that you can import all your essential packages with one line of code and focus on what is important? The solution is called PyForest. PyForest is a lazy import. As the name says, it imports the most popular Data Science libraries for Python. The PyForest developers aim to import 99% of all the most used libraries.
Sounds great, right? However, what if you don’t use all the libraries? Why would you import all of them? The good news is that PyForest will only import the libraries if you use them. For this reason, there is no reason to worry about slowing down your computer. Since the libraries are not imported unless you use their functions or methods, this is a better solution than copying and pasting code from other projects.
Installation
Now, how to use this magic solution? Just as easy as it gets. Pyforest can be installed from Pypl. You can type the following command on your terminal:
pip install pyforest
If you are on Jupyter Notebook, you can type:
!pip install pyforest 
To import, you can use
import pyforest
or
from pyforest import *
These options should work the same way, but you know, Python can be tricky sometimes. If one way doesn’t work, you can always try another. Voilá, you have some of the most important libraries, and you can focus on your project.
But what is actually being imported?
The good news is that the list is long, and to mention a few, it includes Pandas, NumPy, Matplotlib, Seaborn, Sklearn, Keras, NLTK, and the list goes on and on. The coolest part, in my opinion? They use aliases that are standard conventions for Data Scientists, such as importing Pandas as pd and NumPy as np. Life can be effortless!
You can find the complete list of libraries typing lazy_imports() and you will be able to see the full list.
Adding more libraries to PyForest
As we can see, there is a large variety of libraries, and this should cover most of your project. However, some essential libraries are missing. We can quickly fix that by manually adding your favorite libraries. You can try the following steps to add libraries that don’t come initially with PyForest.
First, go to your terminal and type:
pip show pyforest
You will see that the terminal is going to return the location of the PyForest directory. If you are using macOS, you can type Command+Space and paste the directory address. Find the file called _imports.py and add all the libraries you need.
Done! You will now have all your favorites libraries and worry about what matters for your project. I created a micro project — and you can find it here — where I show how I used PyForest without importing anything from other libraries. Remember that if you want to run the Jupyter Notebook, you will have to install PyForest in your environment.