Goal: Demonstrate a basic conda environment creation workflow by creating a Python environment that contains the numpy and pandas packages.
General Process
[salexan5@mblog1 ~]$ module load miniconda3/24.3.0 [salexan5@mblog1 ~]$ conda search python [salexan5@mblog1 ~]$ conda create -n py_env [salexan5@mblog1 ~]$ conda activate py_env (py_env) [salexan5@mblog1 ~]$ conda install python=3.12.4 (py_env) [salexan5@mblog1 ~]$ python --version Python 3.12.4 (py_env) [salexan5@mblog1 ~]$ conda search numpy (py_env) [salexan5@mblog1 ~]$ conda install numpy (py_env) [salexan5@mblog1 ~]$ python -c "import numpy; print(numpy.__version__)" 1.26.4 (py_env) [salexan5@mblog1 ~]$ conda deactivate [salexan5@mblog1 ~]$
Search for Packages
[salexan5@mblog1 ~]$ conda search python Loading channels: done # Name Version Build Channel python 2.7.13 hac47a24_15 pkgs/main ... python 3.12.3 h996f2a0_1 pkgs/main python 3.12.4 h5148396_1 pkgs/main
Notice: Although Python version 2 has been deprecated, it is still used for old packages/modules/scripts. You can create a conda environment that provides this old, no longer supported version.
This is how ARCC provides this version on the cluster.
(py_env) [salexan5@mblog1 ~]$ conda search numpy Loading channels: done # Name Version Build Channel numpy 1.9.3 py27_nomklhbee5d10_3 pkgs/main ... numpy 1.26.4 py39heeff2f4_0 pkgs/main
Create an Environment
[salexan5@mblog1 ~]$ conda create -n py_env Channels: - defaults Platform: linux-64 Collecting package metadata (repodata.json): done Solving environment: done ## Package Plan ## environment location: /home/salexan5/.conda/envs/py_env Proceed ([y]/n)? y
Note the location that the environment will be saved to: environment location: /home/salexan5/.conda/envs/py_env
Create an Environment: Proceed
Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate py_env # # To deactivate an active environment, use # # $ conda deactivate
Note the command required to activate your environment: conda activate py_env
This will be required every time you wish to use it.
Activate an Environment
[salexan5@mblog1 ~]$ conda activate py_env (py_env) [salexan5@mblog1 ~]$
Note how the command line prompt has changed once the environment has been activated: (py_env) [...]
This indicates the name of the conda environment that is currently active.
Conda Install a Version of Python
(py_env) [salexan5@mblog1 ~]$ conda install python=3.12.4
Note all the addition dependencies/libraries that are being installed into the environment
Lets check the version installed, within are active environment.
(py_env) [salexan5@mblog1 ~]$ python --version Python 3.12.4
Conda Install the numpy Package
(py_env) [salexan5@mblog1 ~]$ conda install numpy
Again, note all the addition dependencies/libraries that are being installed into the environment
If no package version is defined, typically it’ll install the latest version.
Lets check the version installed, within are active environment.
(py_env) [salexan5@mblog1 ~]$ python -c "import numpy; print(numpy.__version__)" 1.26.4
Conda Deactivate your Environment
(py_env) [salexan5@mblog1 ~]$ conda deactivate [salexan5@mblog1 ~]$
Note how the command line prompt has changed, reverting back to before being activated: [...]
The conda environment is no longer activate and can not be used.
[salexan5@mblog1 ~]$ python --version Python 3.12.2 [salexan5@mblog1 ~]$ python -c "import numpy; print(numpy.__version__)" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'numpy'
Using the Environment
[salexan5@mblog1 ~]$ module load miniconda3/24.3.0 [salexan5@mblog1 ~]$ conda activate py_env (py_env) [salexan5@mblog1 ~]$ python --version Python 3.12.4 (py_env) [salexan5@mblog1 ~]$ python -c "import numpy; print(numpy.__version__)" 1.26.4 (py_env) [salexan5@mblog1 ~]$ conda deactivate [salexan5@mblog1 ~]$
Note how the conda environment must be activated to use it.
Adding to an Existing Environment
[salexan5@mblog1 ~]$ module load miniconda3/24.3.0 [salexan5@mblog1 ~]$ conda activate py_env (py_env) [salexan5@mblog1 ~]$ conda install pandas (py_env) [salexan5@mblog1 ~]$ python py_test.py Python: 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:12:24) [GCC 11.2.0] Numpy: 1.26.4 Pandas: 2.2.2 (py_env) [salexan5@mblog1 ~]$ conda deactivate
Prev | Workshop Home | Next |