Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Log on to your SAIL desktop.
  2. Click on the Start menu (the little Windows icon on the bottom left) → Anaconda3 (64-bit) → Anaconda Prompt (Anaconda3). This will open a command line window with a line of text like:
    1. (base) C:\Users\<your username will be here>
  3. Activate your conda environment by typing the following in the same command line window:
    1. conda activate P:\<your username here>\<name of your new environment>
    2. So, if my username is 'leal' and I created an environment called 'mynewenv' in a folder called 'conda-envs', I would use the command:
      1. conda activate P:\leal\conda-envs\mynewenv
    3. You will know when the environment is activated because the window will show a line of text like:
      1. (P:\<your username>\<your environment name>) C:\Users\<your username>
  4. Outside your SAIL desktop, go to Google and search '<name of the package you want to install> anaconda'.
    1. For example, if I want to install the package 'recordlinkage', I would search on Google for 'recordlinkage anaconda'.
  5. Select the Google result from anaconda.org; this should take you directly to the Anaconda page for the package.
  6. On the page, there will be a command that tells you how to install it. Sticking with the recordlinkage example, the webpage shows me that the command to install is:
    1. conda install -c conda-forge recordlinkage
  7. Go back to your SAIL desktop and type this installation command into your Anaconda Prompt window, hitting 'Enter'.
  8. Wait for Anaconda to ask you if you want to proceed - hit 'y' on your keyboard and then press 'Enter'.
  9. Your package is installed! 


...


Connecting to DB2 from a Python version > 3.7

There is a known problem with the ibm_db package compiled for Python versions above 3.7, which means we need to do some extra things so we can connect to it from our notebooks.

As a prerequiste, your Anaconda environment will need sqlalchemy, ibm_db, and ibm_db_sa packages installed.

You can then run this script (replacing your username and password in the variables) to connect to db2.

Code Block
languagepy
import os 
import sys
rootpath = [x for x in sys.path if x.split(os.sep)[-1] == "site-packages"][0]
dllpath = f"{rootpath}\\clidriver\\bin"
os.add_dll_directory(dllpath)

import ibm_db
import ibm_db_dbi
import ibm_db_sa
import pandas as pd

from sqlalchemy import create_engine, text

uid = "YOUR USERNAME HERE"
pwd = "YOUR PASSWORD HERE"

database = "pr_sail"
hostname = "db2.database.ukserp.ac.uk"
port = "60070"
security = "ssl"
ssl_client_keystoredb = r"R:\UKSeRP\DB2_SSL\chi.kdb"
ssl_client_keystash = r"R:\UKSeRP\DB2_SSL\chi.sth"
conn_str = (
    f"db2+ibm_db://{uid}:{pwd}@{hostname}:{port}/{database}"
    f"?Security={security}"
    f"&SSLClientKeystoredb={ssl_client_keystoredb}"
    f"&SSLClientKeystash={ssl_client_keystash}"
)

engine = create_engine(conn_str)

sql = "SELECT * FROM syscat.tables LIMIT 1"

with engine.connect() as conn:
    ResultProxy = conn.execute(text(sql))
    results = ResultProxy.fetchall()
    df = pd.DataFrame(results, columns=ResultProxy.keys())

print(df)

The reason for this problem is explained in this GitHub issue: https://github.com/ibmdb/python-ibmdb/issues/887


...

FAQs


Can i install R packages from CRAN?

...