Menu
  • Home
  • About Me
  • Blog
  • Github
  • LinkedIn

Python for Algorithmic Trading – Conda as a Package Manager (1)

January 31, 2022January 31, 2022

There are tools and strategies available that help with the Python deployment issue.

Package managers like pip or conda help with the installing, updateing, and removing of Python packages. They also help with version consistency of different packages.

Conda as a Package Manager

Although Conda can be installed alone, an efficient way of doing it is via Miniconda, a minimal Python distribution that includes Conda as a package and virtual environment manager.

Installing Miniconda

Using Ubuntu-based Docker container

docker run -it -h pyalgo -p 11111:11111 ubuntu:latest /bin/bash

apt-get update; apt-get upgrade -y

apt-get install -y gcc wget

cd root

wget \
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
-O miniconda.sh

bash miniconda.sh
You should see this message

After reviewing the license agreement, approve the terms by answering yes:

Do you accept the license terms? [yes|no]
[no] >>> yes

Miniconda3 will now be installed into this location:
/root/miniconda3
 - Press ENTER to confirm the location
 - Press CTRL-C to abort the installation
 - Or specify a different location below


Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes

no change     /root/miniconda3/condabin/conda
no change     /root/miniconda3/bin/conda
no change     /root/miniconda3/bin/conda-env
no change     /root/miniconda3/bin/activate
no change     /root/miniconda3/bin/deactivate
no change     /root/miniconda3/etc/profile.d/conda.sh
no change     /root/miniconda3/etc/fish/conf.d/conda.fish
no change     /root/miniconda3/shell/condabin/Conda.psm1
no change     /root/miniconda3/shell/condabin/conda-hook.ps1
no change     /root/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change     /root/miniconda3/etc/profile.d/conda.csh
modified      /root/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

If you'd prefer that conda's base environment not be activated on startup,
   set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Miniconda3!

You might want to update conda since the Miniconda installer is in general not as regularly updated as conda itself:

export PATH="/root/miniconda3/bin/:$PATH"
conda update -y conda
echo ". /root/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
bash

(base) root@pyalgo:~# python

Basic Operations with Conda

# Installing Python
conda install python=x.x

# Installing a package
conda install $PACKAGE_NAME

# Updating a package
conda update $PACKAGE_NAME

# Removing a package
conda remove $PACKAGE_NAME

# Updating conda itself
conda update conda

# Searching for packages
conda search $SEARCH_TERM

# Listing installed packages
conda list

Install package

conda install numpy

# Install multiple packages
conda install -y ipython matplotlib pandas \
pytables scikit-learn scipy
IPythonAn improved interactive Python shell
matplotlibThe standard plotting library for Python
NumPyEfficient handling of numerical arrays
pandasManagement of tabular data, like financial time series data
PyTablesA Python wrapper for the HDF5 library
scikit-learnA package for machine learning and related tasks
SciPyA collection of scientific classes and functions

Conda as a Virtual Environment Manager

The virtual environment management allows to execute legacy Python like Python 2.7 although the support for Python 2.7 has ended.

# Creating a virtual environment
conda create --name $ENV_NAME

# Activating an environment
conda activate $ENV_NAME

# Deactivating an environment
conda deactivate $ENV_NAME

# Removing an envirnmonet
conda env remove --name $ENV_NAME

$ Exporting to an environment file
conda env export > $FILE_NAME

# Creating an environment from a file
conda env create -f $FILE_NAME

# Listing all environment
conda info --envs

example code for creating an environment called py27, installing IPython, and executing a line of Python 2.7.x code:

conda create --name py27 python=2.7
conda activate py27
pip install ipython

conda as a virtual environment manager allows one to install different Python versions alongside each other.

The default Python installation is not influenced by such a procedure, nor are other environments that might exist on the same machine. All available environments can be shown via:

conda info –envs:

You can share the environment information with other to export with yml format.

conda activate py27
conda env export --no-builds > py27.yml
cat py27.yml

In the next post, I’m going to write how to create containerized file system that includes an operating system (Ubuntu), runtime (Python), additional system and development tools, and further Python libraries and packages as needed.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts
  • ChinguTalkBot v0.1.0: Setting up AWS Cognito with CDK for User Authentication
  • Phoenix & Elixir: Fix PostgreSQL connection refused
  • Demo: Git Log with Shell script to create a release notes
  • Metasploit
  • CyberSecurity Lab – Online Password Attack

Archives
  • March 2024
  • May 2023
  • April 2023
  • February 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
Categories
  • Amazon Interview (3)
  • Ansible (3)
  • AWS (9)
  • Azure (9)
  • Certification (2)
  • ChinguTalkBot Project (1)
  • cybersecurity (3)
  • Data analytics (6)
  • Demo Videos (6)
  • Docker (5)
  • Git (1)
  • GitLab (1)
  • Golang (3)
  • JavaScript (2)
  • Jenkins (4)
  • PowerShell (1)
  • Python (10)
  • Terraform (11)
  • Uncategorized (9)

©2025 | Powered by WordPress and Superb Themes!