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 virtualenv
Navigate 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 myenv
Once 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.txt
After installation, you can verify that the packages are installed correctly in your virtual environment by running:
pip list
This 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:
deactivate
This command will return you to your global Python environment.