1. Maintaining conda environment

Python packages can evolve rapidly with time. It can happen that once you update an package, many of your codes crash. Therefore, it could be wise to maintain some virtual environment that the packages are frozen (i.e., you never update them). I usually maintain one of such virtual environment for each project (e.g., when preparing the analyses for one paper) for the sake that the results can be easily reproduced.

We can create such virtual environments using the Anaconda package. For linux users, go to the Download page to download the installer, which is a .sh file. You can move it to the directory that you want to install it, and then type

chmod +x installer.sh
./installer.sh

This should be able to complete the installation.

You can also use wget to download the installer:

wget https://repo.anaconda.com/archive/Anaconda3-latest-Linux-x86_64.sh
bash Anaconda3-latest-Linux-x86_64.sh

Then you can create/remove an conda environment by typing

conda create --name environment_name
conda remove --name environment_name --all

and then (de-)activate the environment by typing

conda activate environment_name
conda deactivate

After you activate an environment, you can install/remove a package from that environment by typing

# installing package
pip install packagename

# removing packages
conda remove --name environment_name packagename

To list all the environment you have, type:

# list available environments
conda info --envs

# list all available packages in the current environment
conda list

2. Using Jupyter Notebook from a Remote Server

You need to install Jupyter Notebook in the remote sever (e.g., under a conda environment) by typing

pip install jupyter

At the remote server, launch Jupyter notebook by typing

jupyter notebook --no-browser --port=XXXX

Remember to activate the conda environment in the remote server before doing this step.

Here XXXX is a for digit port number, for example, 8080. In the local computer, setup ssh tunnel by typing

ssh -L XXXX:localhost:XXXX remoteUSRNAME@remoteDOMAIN

Then you can open a web browser in the local computer, and connect to http://localhost:XXXX/logout to launch your remote Jupyter Notebook. You will be asked to insert a token. From the remote sever, you can type jupyter notebook list in the command line to list all of the token you have, and then copy the one that corresponds to the port you are using to the web browser.