# Setup Python Environment In my book, [Hands-On Machine Learning with Scikit-Learn and Scientific Python Toolkits](https://amzn.to/3JiQenP), I make use of libraries such as Pandas, NumPy, etc. There are multiple ways to install the needed libraries. For example you can: - Install via Miniforge (I prefer this) - Install via Anaconda/Miniconda (Not too bad) - Install without virtual environments (Not my cup of tea) ## Install via Miniforge (Virtual Environment) First you need to install [Miniforge](https://github.com/conda-forge/miniforge) on your computer. You will find the right installer at the [following link](https://github.com/conda-forge/miniforge) for your operating system and architecture. For example, they have installers for Windows, Linux, OSX (Intel) and OSX (Apple Silicon). Now that you have installed Miniforge, it is time to create a new virtual environment. Let's call it `scikitbook`, and we will be using Python version 3.6. To create the environment, go to your terminal (for example, on OSX, open Terminal). Then type the following command into the terminal: ```python conda create -n scikitbook python=3.6 ``` Note: Newer versions of Python should work too, but the code in the book is tested on 3.6, so let's stick to that version. Now you need to activate the environment you have just created: ```python conda activate scikitbook ``` Then, you need to install NumPy, SciPy, Pandas, etc. One way is to follow the instructions on page 27 in [Hands-On Machine Learning with Scikit-Learn and Scientific Python Toolkits](https://amzn.to/3JiQenP): ```python pip install --upgrade numpy==1.17.3 pip install --upgrade scipy==1.3.1 pip install --upgrade pandas==0.25.3 pip install --upgrade scikit-learn==0.22 pip install --upgrade matplotlib==3.1.2 pip install --upgrade seaborn==0.9.0 ``` Alternatively, you can clone the book's GitHub repo here, [PacktPublishing/Hands-On-Machine-Learning-with-scikit-learn-and-Scientific-Python-Toolkits](https://github.com/PacktPublishing/Hands-On-Machine-Learning-with-scikit-learn-and-Scientific-Python-Toolkits). Then you can run the following command: ```python pip install --upgrade -r requirements.txt ``` You are all set now. Whenever you restart your computer, you just need to run the following command to activate the environment: ```python conda activate scikitbook ``` ## Install via Anaconda (Virtual Environment) The exact instructions above work for [Anaconda](https://www.anaconda.com/) too. The only difference is that you need to install the Anaconda/Miniconda from this [link](https://docs.anaconda.com/anaconda/install/index.html) instead of Miniforge ## Install without virtual environments Just skip the virtual environment installations, and just install Python 3.6 on your system. Then run the following `pip` commands: ```python pip install --upgrade numpy==1.17.3 pip install --upgrade scipy==1.3.1 pip install --upgrade pandas==0.25.3 pip install --upgrade scikit-learn==0.22 pip install --upgrade matplotlib==3.1.2 pip install --upgrade seaborn==0.9.0 ``` Again, you can use the book's GitHub repo here, [PacktPublishing/Hands-On-Machine-Learning-with-scikit-learn-and-Scientific-Python-Toolkits](https://github.com/PacktPublishing/Hands-On-Machine-Learning-with-scikit-learn-and-Scientific-Python-Toolkits). Then run the following command instead of the multiple pip commands above: ```python pip install --upgrade -r requirements.txt ``` Feel free to contact me if anything is still not clear. Links to Amazon are affiliate links. --- Tarek Amr