Python on MobaXterm
Okay, I lied...
when I said my next post was going to be on virtual environments and
conda env. After teaching a class of budding bioinformaticists, I realized that not every Windows user in the class was a Windows 10 user. Therefore, my last blog does little to help them.Therefore, I am attempting another route to allow Windows users to have the luxury of a "Linux-like' environment.
From their site, MobaXterm describes itself as an "Enhanced terminal for Windows with X11 server, tabbed SSH client, network tools and much more". To regular people that don't know what all that means; it allows Windows users an simpler way of connecting with remote systems.
MobaXterm is built on Cygwin. Cygwin is a set of tools and Dynamically-Linked Library (DLL) that provides tools and functionality much like Linux. It is not Linux though, just Linux-like.
Since MobaXterm runs on Cygwin, Windows users can use Linux commands like
ls (instead of Windows'
dir) to list the contents of a directory. This is important to me, in a classroom environment, because everyone can potentially be working off the same set of commands line arguments. Not a set for the MacOS & Linux users, and another set for the Windows users. This means less downtime during instruction, which ultimately means more content covered.
Installation of MobaXterm
- Navigate to wherever you saved the MobaXterm download.
- Right-click the ZIP file, and select 'Extract All ...'
- Decide where to extract the contents to.
Once it finished, it should automatically open to the contents.
- Double-click on the installer (it has '.msi' on the end if the extensions are visible) and finish the install.
The First Problem
In some (not all) cases, even after installation, the user cannot open a shell. They get a error that says something about CygUtils plugin not detected. Users should follow the link in the window (or here) to download it.
Now comes the fine print of that window: "[...] put the downloaded file in the same folder than [sic] MobaXterm executable:".
If you are experiencing this error, do the following:
sto search for MobaXterm
- Right-click the result and select 'Open file location'
- In the window that opens up, right-click MobaXterm Personal Edition and select 'Open file location' again.
- Now, copy the CygUtils.plugin file you downloaded earlier into this file.
- Restart MobaXterm if it is still open.
The Second Problem
Part A (Anaconda not in PATH):
MobaXterm does not 'inspect' Windows' PATH environment variable by default. The PATH variable is just a list of all the places the computer should look to find a file.
Now, towards the end of your Anaconda install, the installer asks if you want to add Anaconda to my PATH. This box is not checked by default. In some cases, it is even red and says 'Not Recommended'. This is because Anaconda makes no assumptions about the person having administrative access to the computer.
To see if Anaconda was added to your PATH,
r to run CMD. When the command prompt opens, enter the following command:
If the prompt says
"INFO: Could not find files for the given pattern(s).", Anaconda is not in your PATH.
If it anything that looks like a file path comes up, Anaconda was added to your PATH. If you checked that box or Anaconda is in your PATH, move onto the part b).
Now, for those that do not have Anaconda in their path, there is an easy way to fix this. By default, MobaXterm uses
/home/moba as its home directory. Let's check it out:
- Open MobaXterm
- type the command
cdto make sure you are at your home directory
ls -ato see if there is a file called
.bashrcin the directory
- If there isn't; do
- If there isn't; do
Paste the following command:
echo "export PATH=/drives/c/ProgramData/Anaconda3/:/drives/c/ProgramData/Anaconda3/lib/:/drives/c/ProgramData/Anaconda3/Scripts/:/drives/c/ProgramData/Anaconda3/Library/bin:/drives/c/ProgramData/Anaconda3/Library/usr/bin:/drives/c/ProgramData/Anaconda3/Library/mingw-w64/bin:$PATH" >> ~/.bashrc && source ~/.bashrc
Check to see if it worked:
Part B (Anaconda in PATH):
The easiest way to fix this problem (assuming you did a basic install of Anaconda) is the following:
- Open MobaXterm
- Click 'Settings'
- Go to the Terminal tab, and check the box that says 'Use Windows PATH environment'
- Press 'Okay' and restart MobaXterm
- When MobaXterm comes back, type the command
which conda. If something that looks like a file path is returned, you are good to go to the next Problem.
The Third Problem
The last problem is a simple one. MobaXterm defaults to looking for Cygwin's version of Python. While we can type
conda --version and
jupyter --version, we cannot type
To fix this, just paste these two commands:
echo "alias python=python.exe" >> ~/.bashrc
Now we can use Python just like normal:
All these fixes really help, but the problem is that when MobaXterm is restarted, it doesn't automatically
source ~/.bashrc. The final thing we need to do is make one last file using the following command:
echo "if [[ -f ~/.bashrc ]]; then source ~/.bashrc; fi" > ~/.bash_profile
This should make life a little simpler for those Windows users that either can't use the Windows Subsystem for Linux (WSL), don't want to use WSL, or don't have Windows 10. Hopefully this helps.
This time, I promise that my next blog will be on virtual environments and
conda env. Till then, thank you for your time and consideration. Feel free to leave any comments, critiques, or praise in the comments below.