{"id":575,"date":"2020-05-13T14:55:08","date_gmt":"2020-05-13T12:55:08","guid":{"rendered":"http:\/\/calculs.univ-cotedazur.fr\/?page_id=575"},"modified":"2025-01-15T14:19:27","modified_gmt":"2025-01-15T13:19:27","slug":"create-your-python-environment","status":"publish","type":"page","link":"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&lang=en","title":{"rendered":"Create your Miniconda environment (Python, R)"},"content":{"rendered":"\n<p>We strongly encourage users\nto create their own Python environment with the Miniconda distribution rather\nthan using the centralized Python distributions available with the cluster\nmodules. You can work with the latest updates faster, get performance\nimprovements and avoid possible incompatibilities between different modules.<\/p>\n\n\n\n<p>With Miniconda, you can create your own Python or R environment and install the packages you need there. You can even repeat the operation for different projects and thus have an environment specific to each.<\/p>\n\n\n\n<p>Miniconda is a minimalist version of Anaconda and includes a basic Python and the Conda package manager. You can then install additional packages by following the procedure below.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_11 counter-hierarchy counter-decimal ez-toc-grey\">\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Prerequisites\" title=\"Prerequisites \">Prerequisites <\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Create_the_environment\" title=\"Create the environment\">Create the environment<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Activate_your_environment\" title=\"Activate your environment\">Activate your environment<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Add_a_package\" title=\"Add a package\">Add a package<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Install_R_packages\" title=\"Install R packages\">Install R packages<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#List_your_environments\" title=\"List your environments\">List your environments<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Deactivate_your_environment\" title=\"Deactivate your environment \">Deactivate your environment <\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Delete_an_environment\" title=\"Delete an environment\">Delete an environment<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/calculs.univ-cotedazur.fr\/?page_id=575&amp;lang=en#Job_example\" title=\"Job example\">Job example<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To use the miniconda commands, you must first load the miniconda module on the login node:<\/p>\n\n\n\n<pre class=\"wp-block-verse\">module load miniconda<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Create_the_environment\"><\/span>Create the environment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Create the environment by giving it a path (here <em>\/workspace\/$USER\/my_env<\/em>) and choosing its Python version (here 3.7):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">conda create python=3.7 --prefix \/workspace\/$USER\/my_env<\/pre>\n\n\n\n<p>You can also install it in another directory. For instance, you can share an environment with the other users of your project. To do so, you should install it in your shared directory in \/workspace\/your_group_name:<\/p>\n\n\n\n<pre class=\"wp-block-verse\"> conda create python=3.7 --prefix \/workspace\/your_group_name<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Activate_your_environment\"><\/span>Activate your environment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-verse\">conda activate \/workspace\/$USER\/my_env<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Add_a_package\"><\/span>Add a package<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-verse\">conda install package_name<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Install_R_packages\"><\/span>Install R packages<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can also install the R packages you want in your Miniconda environment. To do this, you must first install R there, then the packages:<\/p>\n\n\n\n<pre class=\"wp-block-verse\">conda install -c r r r-essentials\nR\ninstall.packages(\"package_name\", dependencies=TRUE)<\/pre>\n\n\n\n<p>Packages will be installed by default into \/home\/$USER\/.conda\/envs\/r_env\/lib\/R\/library<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"List_your_environments\"><\/span>List your environments<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-verse\">conda env list<\/pre>\n\n\n\n<p>The asterisk in front of one of the listed environments indicates which one is currently in use.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Deactivate_your_environment\"><\/span>Deactivate your environment <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-verse\">conda deactivate<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Delete_an_environment\"><\/span>Delete an environment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here, we delete an environment in <em>\/workspace\/$USER\/my_env<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-verse\">conda env remove -p \/workspace\/$USER\/my_env<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Job_example\"><\/span>Job example<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Put the following content into a file, named for example <strong>job.slurm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\">#!\/bin\/sh\n#SBATCH --job-name=python_job_conda\n#SBATCH --time=0-00:03:00\n#SBATCH --account=project_name\n#SBATCH --output=my_job_output.txt\n#SBATCH --ntasks=1\n#SBATCH --partition=cpucourt\n\n module purge\n module load miniconda\n\n conda activate \/workspace\/$USER\/my_env\n python \/workspace\/$USER\/jobs\/my_code.py\n conda deactivate<\/pre>\n\n\n\n<p>Then submit this job by entering <strong>sbatch job.slurm<\/strong> on login-hpc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We strongly encourage users to create their own Python environment with the Miniconda distribution rather than using the centralized Python distributions available with the cluster modules. You can work with the latest updates faster, get performance improvements and avoid possible &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":580,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/pages\/575"}],"collection":[{"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=575"}],"version-history":[{"count":12,"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/pages\/575\/revisions"}],"predecessor-version":[{"id":2866,"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/pages\/575\/revisions\/2866"}],"up":[{"embeddable":true,"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=\/wp\/v2\/pages\/580"}],"wp:attachment":[{"href":"https:\/\/calculs.univ-cotedazur.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}