How To
Summary
You can install python packages into custom environment on Air-gapped CPD by following the steps below.
Steps
- Open a temporary notebook and run following code to create an empty conda channel.
Code snippet:channel_dir="/project_data/data_asset/empty_conda_channel" !mkdir -p $channel_dir/noarch with open(channel_dir+"/noarch/repodata.json","w") as f : f.write('{ "channeldata_version": 1, "packages": {}, "subdirs": ["noarch"] }') !bzip2 -k $channel_dir/noarch/repodata.json
- Prepare the packages through a machine connected to the Internet. Now let's say you want to install "nltk". There are two ways to download the packages, use whichever suits your situation.
1: Download the packages by using pip command
2: Download the packages from PyPI via your browser
Example:[root@testenv ~]# pip3 download -d ./nltk nltk Collecting nltk Downloading nltk-3.8.1-py3-none-any.whl (1.5 MB) |████████████████████████████████| 1.5 MB 1.3 MB/s Saved ./nltk/nltk-3.8.1-py3-none-any.whl Collecting tqdm Downloading tqdm-4.64.1-py2.py3-none-any.whl (78 kB) |████████████████████████████████| 78 kB 5.4 MB/s Saved ./nltk/tqdm-4.64.1-py2.py3-none-any.whl Collecting joblib Downloading joblib-1.2.0-py3-none-any.whl (297 kB) |████████████████████████████████| 297 kB 7.2 MB/s Saved ./nltk/joblib-1.2.0-py3-none-any.whl Collecting regex>=2021.8.3 Downloading regex-2022.10.31-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (769 kB) |████████████████████████████████| 769 kB 4.8 MB/s Saved ./nltk/regex-2022.10.31-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Collecting click Using cached click-8.1.3-py3-none-any.whl (96 kB) Saved ./nltk/click-8.1.3-py3-none-any.whl Successfully downloaded nltk tqdm joblib regex click [root@testenv ~]# [root@testenv ~]# ls nltk click-8.1.3-py3-none-any.whl nltk-3.8.1-py3-none-any.whl tqdm-4.64.1-py2.py3-none-any.whl joblib-1.2.0-py3-none-any.whl regex-2022.10.31-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl [root@testenv ~]#
- Upload the packages to your project from UI. You can refer the uploaded files in /project_data/data_asset.
- Create a custom environment and edit it to install packages.
Example:# Modify the following content to add a software customization to an environment. # To remove an existing customization, delete the entire content and click Apply. # The customizations must follow the format of a conda environment yml file. # Add conda channels below defaults, indented by two spaces and a hyphen. channels: - file:///project_data/data_asset/empty_conda_channel - nodefaults # To add packages through conda or pip, remove the # on the following line. dependencies: # Add conda packages here, indented by two spaces and a hyphen. # Remove the # on the following line and replace sample package name with your package name: # - a_conda_package=1.0 # Add pip packages here, indented by four spaces and a hyphen. # Remove the # on the following lines and replace sample package name with your package name. - pip: - file:///project_data/data_asset/click-8.1.3-py3-none-any.whl - file:///project_data/data_asset/joblib-1.2.0-py3-none-any.whl - file:///project_data/data_asset/nltk-3.8.1-py3-none-any.whl - file:///project_data/data_asset/regex-2022.10.31-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - file:///project_data/data_asset/tqdm-4.64.1-py2.py3-none-any.whl
- Open new notebook with custom environment created in Step4.
Additional Information
I specified "/project_data/data_asset" as a file save destination in this technote. This directory is not shared with other project, so the packages are only available inside the project. If you want to share packages with other projects, you can use "/user-home/_global_/config/conda" instead of "/project_data/data_asset". Replace all the directories specified in the steps if you need.
Document Location
Worldwide
[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSHGYS","label":"IBM Cloud Pak for Data"},"ARM Category":[{"code":"a8m50000000ClWMAA0","label":"Analyze-\u003EEnvironments"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"4.5.3"}]
Was this topic helpful?
Document Information
Modified date:
02 March 2023
UID
ibm16959553