In this guide, we'll walk through the steps to create a Python virtual environment and install the necessary libraries for our financial analysis project. Virtual environments in Python are a tool to keep dependencies required by different projects in separate places. This is achieved by creating isolated python virtual environments for them.
First, ensure that you have virtualenv installed. If you don't have virtualenv installed, you can install it using pip:
pip install virtualenvNavigate to your project's directory in the terminal and run the following command to create a virtual environment. Replace myenv with your desired environment name.
virtualenv myenvOnce the environment is created, you need to activate it. The command to activate the virtual environment varies based on your operating system.
-
On Windows:
.\myenv\Scripts\activate
-
On macOS and Linux:
source myenv/bin/activate
With your environment activated, you can now install the required libraries. Run the following commands to install numpy, pandas, yfinance, quantstats, and matplotlib:
pip install -r requirements.txtAfter installation, you can verify that the packages are installed correctly in your virtual environment by running:
pip listThis will show you a list of all installed packages and their versions in your virtual environment.
Once you're done working in the virtual environment, you can deactivate it by running:
deactivateThis command will return you to your global Python environment.