Installing Conda and Creating Python Environment

Photo by AltumCode on Unsplash

Hello, imagine a condition where you are given a Linux machine, but you don’t have the root privileges on also you don’t wish to mess with the system’s Python or it could, you might be working under resource constraint condition, or there are many users on the dedicated machine those are the times where Environment management systems like Conda comes in use. For managing the python Environment.

This is a quick and short article that will help on, how to install the conda locally without sudo or root privileges easy and preferable way to create a conda environment for different versions of Python. So lets Start,

Downloading conda executable from their website. There are two versions either you can download a larger file that comes with the graphical installer in the range of some Five hundreds megabytes or a simple .sh file version which is in the range of 300 MB’s.

If considering the size as an limiting factor, you can click to use their archives and download the miniconda which is in the range of 70MB here download command given below is so with the smaller file OF MINICONDA INSTALLER.

Or using the “wget” which is a command-line download utility that will download the file for you can also download that using the browser also if the above link expires, replace the link below with the latest link, and it will download the executable file for you

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Once Downloaded, we have to convert the file to the executable below command will help you, but conda should be replaced with the name of your conda/miniconda executable.

chmod +x ./conda.sh

Now we will proceed to installation for that use the command mentioned below. It will asks you to hit enter and then will open the agreement keep pressing the space bar to reach at the end of it and accept the terms by typing yes then, proceed.

Remember since we are doing the local installation you can choose the different path for installation otherwise it will by default create a directory in /home/miniconda it will also prompt you with confirmation once done, it will start installing the libraries.

sh ./conda.sh

Once your installation is done, you can close out the terminal and open a new one where you will see “base” mentioned on terminal prompt, if you have chosen to append the conda command in ./bashrc at the last part of installer else you have to initialize the conda each time manually.

Now will head towards Creating the environments, and you can use the command below

conda create -n name_of_env python=version anaconda

Here you can play little smart generally for system-specific Python create two environments based on two major python versions and could name them, for example
For version python3.6, you can name your environment python36, and for version python2.7, name it as python27, which makes it easy to remember also, most programs work easily on these two versions of python

conda create -n python36 python=3.6 anaconda

Then for python 2.7

conda create -n python27 python=2.7 anaconda

Using anaconda at the end of the command will take you a little longer to finish based on your bandwidth, but that’s good enough and save you from installing few mostly used packages since it will preinstall them for you.

Once you have created the environment, you can activate them by using the command below. That will change the terminal prompt that will base the name of your environment.

conda activate name_of_env

Then you can use your environment install packages in it using pip or conda and deactivate the environment by simply typing the command below

conda deactivate name_of_env

Installing package in the environment

conda install name_of_env package pip install package 

To list packages installed

conda list

That was the strategy to tackle the system level python version issues but imagine you are working on a specific project and want to keep track of the dependency getting or being used by that particular project. For this kind of issue, I will guide you with the strategy you can try.

Imagine as an example you wish to work with the GPT2, a large transformer-based language model with 1.5 billion parameters.

Fork the GPT2 git library

git clone https://github.com/nshepperd/gpt-2.git 

Once that’s done, you can create a different environment with your project’s name like here; I have named my environment as gpt2.

conda create -n gpt2 python=3.6 # creating a env

You can also note down that I haven’t used the parameter anaconda at the end, and by that, it only installs few necessary packages for the environment to work also, this finishes in quickly

conda activate gpt2

For example, your package comes with the requirements file. You can pip install the requirement file like in the command below

pip install -r requirements.txt # dependency

We have learned how to use conda in simple and quick short ways to tackle the system-level python version issues, use the project-specific environment, and install it without root privileges. There are more complex way environment management systems that even create the more complex software specific version stacks you can check out about Docker.

And if you have reached this end of the article, Thanks for Reading .. :)

--

--

--

Hello i am Doctoral Fellow at School of Computational and Integrative Sciences(SC&IS) works in the field of Text and Data mining and NLP.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

some of both

Reflections and Advice from a Coding Bootcamp Grad — Five years on

Some Common Bugs to Consider During Mobile App Testing

Which Are The Popular PHP Frameworks In 2021?

Why is the ‘demo’ adaptor missing from the list of

Is Manual Testing in Salesforce Efficient?

Open VDF: Carry Propagate Adders

Flutter Design Patterns: 1 — Singleton

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nitin K. Chauhan

Nitin K. Chauhan

Hello i am Doctoral Fellow at School of Computational and Integrative Sciences(SC&IS) works in the field of Text and Data mining and NLP.

More from Medium

Python Lambda Functions

Python Virtual Environments

Docker Python Hello World

Install Miniconda (Conda) and Python