6.1 Conda Commands
This topic contains common commands used by ADMIN while creating and testing conda environments in Autonomous Databases. Conda is an open-source package and environment management system that enables the use of environments containing third-party Python libraries.
Conda Help
To get help for conda commands, run the command name followed by the
--help
flag.
Note:
The conda command is not run explicitly because the%conda
interpreter provides the conda context.
-
Get help for all conda commands
%conda --help
-
Get help for a specific conda command. Run the following command to get help with the
install
command:%conda install --help
Conda Info
The info
command displays information about the conda
installation, including the conda version and available channels.
%conda
info
Conda Search
The search
command allows the user to search for
packages and display associated information, including the package version and the
channel where it resides.
-
Search for a specific package. Run the following command to search for the package
scikit-learn
.%conda search scikit-learn
-
Search for packages containing 'scikit' in the package name.
%conda search '*scikit*'
-
Search for a specific version of a package.
%conda search 'numpy==1.12'
%conda search 'numpy>=1.12'
-
Search for a specific version on a specific channel.
%conda search conda-forge::numpy
Enhanced Conda Commands
A set of enhanced conda commands in the conda environment lifecycle
management package env-lcm
supports the management of environments
saved to Object Storage, including uploading, downloading, listing, and deleting
available environments.
Help for conda lifecycle environment commands.
%conda
env-lcm --help
Usage: conda-env-lcm [OPTIONS] COMMAND [ARGS]...
ADB-S Command Line Interface (CLI) to manage persistence of conda
environments
Options:
-v, --version Show the version and exit.
--help Show this message and exit.
Commands:
delete Delete a saved conda environment
download Download a saved conda environment
import Create or update a conda environment from saved metadata
list-local-envs List locally available environments for use
list-saved-envs List saved conda environments
upload Save conda environment for later use
Creating Conda Environments
- Use the create command to create an environment
myenv
and install the Python keras package. - Verify that the new environment is created, and activate the environment.
- Install, then uninstall an additional Python package, pytorch, in the environment.
- Deactivate and remove the environment.
Note:
The ADMIN user can access the conda environment from Python and R, but does not have the capability to run embedded Python and R execution commands.create
command, enter create --help
in a
%conda
paragraph.
List Environments
Start by listing the environments available by default. Conda contains default environments with some core system libraries and conda dependencies. The active environment is marked with an asterisk (*).
%conda
env list
# conda environments:
#
base * /usr
conda-pack-env /usr/envs/conda-pack-env
Create Conda Environment
Create conda environment called myenv
with Python 3.10
for OML4Py compatibility and install the keras package.
%conda
create -n myenv python=3.10 keras
Verify Environment Creation
Verify the myenv environment is in the list of environments. The asterisk (*) indicates active environments. The new environment is created but not activated.
%conda
env list
# conda environments:
#
myenv /u01/.conda/envs/myenv
base * /usr
conda-pack-env /usr/envs/conda-pack-env
Activate the Environment
Activate the myenv environment and list the environments to verify the activation. The asterisk (*) next to the environment name confirms the activation.
%conda
activate myenv
Conda environment 'myenv' activated
List the environments available by default.
%conda
env list
# conda environments:
#
myenv * /u01/.conda/envs/myenv
base /usr
conda-pack-env /usr/envs/conda-pack-env
Installing and Uninstalling Libraries
The ADMIN user can install and uninstall libraries into an environment
using the install
and uninstall
commands. For help
with the conda install
and uninstall
commands,
type install --help
and uninstall --help
in a
%conda
paragraph.
Note:
When conda installs a package into an environment, it also installs any required dependencies. As shown here, it’s possible to install packages to an existing environment. As a best practice, to avoid dependency conflicts, simultaneously install all the packages you need in a specific environment.Install Additional Packages
Install the pytorch package into the activated myenv environment.
%conda
install pytorch
List Packages in the Current Environment
List the packages installed in the current environment, and confirm that keras and pytorch are installed.
%conda
list
The output is similar to the following:
# packages in environment at /u01/.conda/envs/myenv:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
_openmp_mutex 5.1 1_gnu
blas 1.0 mkl
.
.
.
fftw 3.3.9 h27cfd23_1
future 0.18.2 py310h06a4308_1
intel-openmp 2021.4.0 h06a4308_3561
keras 2.10.0 py310h06a4308_0
keras-preprocessing 1.1.2 pyhd3eb1b0_0
ld_impl_linux-64 2.38 h1181459_1
libffi 3.3 he6710b0_2
libgcc-ng 11.2.0 h1234567_1
.
.
.
numpy-base 1.23.3 py310h8e6c178_1
openssl 1.1.1s h7f8727e_0
pip 22.2.2 py310h06a4308_0
pycparser 2.21 pypi_0 pypi
python 3.10.6 haa1d7c7_1
pytorch 1.10.2 cpu_py310h6894f24_0
readline 8.2 h5eee18b_0
.
.
.
xz 5.2.6 h5eee18b_0
zlib 1.2.13 h5eee18b_0
The output above has been truncated and does not show the complete list of packages.
Uninstall Package
Libraries can be uninstalled from an environment using the uninstall command. Let’s uninstall the pytorch package from the current environment.
%conda
uninstall pytorch
Verify Package was Uninstalled
List packages in current environment and verify that the pytorch package was uninstalled.
%conda
list
The output shown below does not contain the pytorch
package.
# packages in environment at /u01/.conda/envs/myenv:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
_openmp_mutex 5.1 1_gnu
blas 1.0 mkl
bzip2 1.0.8 h7b6447c_0
ca-certificates 2022.10.11 h06a4308_0
certifi 2022.9.24 py310h06a4308_0
cffi 1.15.1 py310h74dc2b5_0
fftw 3.3.9 h27cfd23_1
future 0.18.2 py310h06a4308_1
intel-openmp 2021.4.0 h06a4308_3561
keras 2.10.0 py310h06a4308_0
keras-preprocessing 1.1.2 pyhd3eb1b0_0
ld_impl_linux-64 2.38 h1181459_1
libffi 3.3 he6710b0_2
libgcc-ng 11.2.0 h1234567_1
libgfortran-ng 11.2.0 h00389a5_1
libgfortran5 11.2.0 h1234567_1
libgomp 11.2.0 h1234567_1
libstdcxx-ng 11.2.0 h1234567_1
libuuid 1.0.3 h7f8727e_2
mkl 2021.4.0 h06a4308_640
mkl-service 2.4.0 py310h7f8727e_0
mkl_fft 1.3.1 py310hd6ae3a3_0
mkl_random 1.2.2 py310h00e6091_0
ncurses 6.3 h5eee18b_3
ninja 1.10.2 h06a4308_5
ninja-base 1.10.2 hd09550d_5
numpy 1.23.3 py310hd5efca6_1
numpy-base 1.23.3 py310h8e6c178_1
openssl 1.1.1s h7f8727e_0
pip 22.2.2 py310h06a4308_0
pycparser 2.21 pypi_0 pypi
python 3.10.6 haa1d7c7_1
readline 8.2 h5eee18b_0
scipy 1.9.3 py310hd5efca6_0
setuptools 65.5.0 py310h06a4308_0
six 1.16.0 pyhd3eb1b0_1
sqlite 3.39.3 h5082296_0
tk 8.6.12 h1ccaba5_0
typing-extensions 4.3.0 py310h06a4308_0
typing_extensions 4.3.0 py310h06a4308_0
tzdata 2022f h04d1e81_0
wheel 0.37.1 pyhd3eb1b0_0
xz 5.2.6 h5eee18b_0
zlib 1.2.13 h5eee18b_0
Removing Environments
If you don’t intend to upload the environment to Object Storage for the
OML users in the database, you can simply exit the notebook session and it will go
out of scope. Alternatively, it can be explicitly removed using the env remove
command. Remove the myenv environment and verify it was removed. A best practice is
to deactivate the environment prior to removal. For help on the env
remove
command, type env remove --help
in the
%conda
interpreter.
-
Deactivate the environment.
%conda deactivate
Conda environment deactivated
-
Remove the environment.
%conda env remove -n myenv
List the environment to see if the environment is removed or not.
env list
# conda environments: # myrenv /u01/.conda/envs/myrenv base * /usr conda-pack-env /usr/envs/conda-pack-env
Remove all packages in environment
/u01/.conda/envs/myenv
.
Specify Packages for Installation
Install Packages from the conda-forge Channel
Conda channels are the locations where packages are stored. They serve as the base for hosting and managing packages. Conda packages are downloaded from remote channels, which are URLs to directories containing conda packages. The conda command searches a set of channels. By default, packages are automatically downloaded and updated from the default channel. The conda-forge channel is free for all to use. You can modify what remote channels are automatically searched. You might want to do this to maintain a private or internal channel. We use the conda-forge channel, a community channel made up of thousands of contributors, in the following examples.
-
Install a specific version of a Package.
To install a specific version of a package, use <
package_name
>=<version
>. -
Create an environment using conda-forge.
%conda create -n mychannelenv -c conda-forge python=3.10 activate mychannelenv
-
Install a package from conda-forge by specifying the channel.
%conda install scipy --channel conda-forge
-
Install a specific version of a package.
%conda install scipy=0.15.0
Parent topic: Install Third-Party Packages