Setting up python in a linux machine without administrative rights

Juliano Genari de Araujo
3 min readApr 7, 2021

As a python developer and a data scientist quite often i have to use a remote linux machine without having administrative rights, many of those machines will have an out dated version of python, often without tools like pip, in some cases not even that is available. In those situations there is a simple path to setup a fully functional, up to date, python environment to run your code without leaving your user’s home folder.

So let’s begin in our path…

Setting up an Anaconda environment using Miniconda

Miniconda is an excellent tool to uses like this, it is a portable version of the Anaconda distribution maintaining all the functionality and removing possible useless packages, it preserves just the core of Anaconda for you to choose what packages to install on top.

To install miniconda we first need to download it, this can be dome with wget:

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

Or using cURL:

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

Use each one is available in your system (usually all linux systems have at least one of the two available).

(Assuming you have an x86_64 linux distro, this will not work with older x86 systems or ARM based systems, like raspberry pi, there is an ARM version of miniconda but it is not supported as well as the x86_64 version.)

After that we need to mark the executable bit in the downloaded file:

chmod a+x Miniconda3-latest-Linux-x86_64.sh

Than we can run the installation:

./Miniconda3-latest-Linux-x86_64.sh

First it will ask you to review the license (you can take your time to read it, or not, I normally just hold Enter until it ask’s me to type yes to agree), than it will ask you where you want to install it, the default folder is ~/miniconda3, if you want you can change it, or not, ether way it will work the same.

After it finish unpacking everything it will asks you if you want to initialize Miniconda3, the default answer is no, but you will want to answer yes to that, that way it will add the necessary commands to your .bashrc file so that every time you open a shell session your conda environment will be automatically initialized.

Now just close the current shell (if you are remotely logged just close your ssh session and connect again), and BAM, when you open a new shell the a wild (base) will appear before your prompt indicating you are in the base Anaconda environment:

Installing packages

Installing packages in an Anaconda environment can be done in multiple ways, but the two most used is using the conda command:

conda install <pakage_name>

This will pull packages from the Anaconda repository, and most popular libraries are available trough it.

Or using the popular pip command (the python -m is needed to use the pip inside the conda environment):

python -m pip install <package_name>

This will pull packages from the PyPI repository.

One important difference between the two repositories is that the Anaconda repository is curated, so every package in it will be almost guaranteed to work properly and safely, PyPI is a way vaster repository as it is a public repository, so more obscure packages can not work or even damage your system, so be careful using pip and always search about a package before installing it.

Just start coding

You now have a fully functional, up to date, python environment, just use it, you can run your scripts or enter a python terminal using the python command, or enter a interactive python session using the ipython command, you can even install jupyter on it using the conda install command and use jupyter notebooks on it.

--

--