The article “Setting Up Python On Your System” was originally posted on QuantInsti blog.
Python is a versatile programming language that is comparatively easier to learn and program. One of the advantages of Python is that there are a host of libraries that the user can install on their system so that they don’t have to code from scratch.
These libraries are updated time and again to make sure everything is working smoothly. But there can be occasions where some libraries might become incompatible with each other due to an update in one library.
You can use this article to set up your local Python environment which is similar to the Quantra portal. The Quantra portal contains all the recommended packages for quant analysis and algo trading.
This blog covers the following sections. If you are already familiar with Anaconda installation or have already installed Anaconda, then you can straight away go to the ‘Set the Python Version and Install Packages’ section.
If you want to explore a particular issue, you can head directly to the links below:
Python Installation Steps
Install and Run Anaconda
- Install Anaconda on Windows
- Install Anaconda on Mac
- Troubleshooting Anaconda Installation Issues
Set the Python Environment
- Set the Python Version and Install Packages
- Troubleshooting Tips For Setting Environment
For Quantra users
- How to Run Files Included in the Download Section of Quantra Courses
- What are Different File Types in data_module?
- Troubleshooting Notebooks
- How will you access the CSV files stored in the data_modules?
- How to access the functions stored in the data_modules folder?
Anaconda helps you in organising your code, write simple explanations to the code in markdown cells, as well as give control over how the program should be run.
You can also use the Anaconda prompt to install Python packages easily.
Install Anaconda on Windows
If you have already installed Anaconda, you can skip the sections and head straight to the section on setting the python version. Visit QuantInsti to view the Google slides.
Remember that each environment you create will have a particular name. Right now it is “base”.
You can head to the ‘Set the Python Version and Install Packages’ section now. If Anaconda didn’t install correctly, head to this section.
Install Anaconda on Mac
Remember that each environment you create will have a particular name. Right now it is “base”.
You can head straight to the ‘Set the Python Version and Install Packages’ section now. If Anaconda didn’t install correctly, head to this section. Visit QuantInsti to view the Google slides.
Troubleshooting Anaconda Installation Issues
One of the common issues we have encountered while installing Anaconda is the issue of file location. It is generally recommended to install Anaconda where you are installing Python.
Sometimes, your system might not be able to install Anaconda due to the system requirements. In that case, you can pick one of the earlier versions from this link.
Now that Python and Anaconda have been installed, we will modify the Python environment to the same environment used by Quantra. Let us see the process in the next section.
Set the Python Version and Install Packages
Let us not now create an environment in Python using the Anaconda prompt. Visit QuantInsti to view the Google slides.
The commands you have to type are listed below:
A) For creating new environment with machine learning libraries:
conda env create -f https://quantra.quantinsti.com/downloads/machinelearning/environment.yml
B) For creating new environment without machine learning libraries:
conda env create -f https://quantra.quantinsti.com/downloads/general/environment.yml
2. For activating new environment: conda activate quantra_py
3. For opening Jupyter notebook in new environment: jupyter notebook
Now you can open any notebook and start working on it right away.
Troubleshooting Tips For Setting Environment
While installing the packages, you might get an error message saying “Windows C++ or higher is needed to install packages. You can simply copy-paste the link and download the build tools.
Click on the setup file and make sure you have selected the “C++ build tools” checkbox and further selected the 5 “optional” tools as well, as seen in the screenshot below.
Follow the instructions during setup and the required packages will be installed. You can then try installing the Python packages again, and this time the set-up will be complete.
For an optimum user experience, you should extract all the files to the root directory where Python is installed. For example, if the Python installation is in the folder “C:Usersrekhi”, then extract the files to this folder itself.
If you want to remove an existing environment, you can do it in the following manner.
- Deactivate the environment
- Run the following command: conda remove –name quantra_py –all
Note: Here, the environment name is “quantra_py”. You can write the name of the environment which you want to remove.
Once the environment is set up, you can run all the notebooks in the downloaded zip files from your course.
Visit QuantInsti for details on the exclusive section for Quantra learners.
Disclosure: Interactive Brokers
Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.
This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.