Windows Subsystem for Linux (WSL) allows you to install Linux distributions such as Ubuntu under Windows. The root filesystem you see under WSL is located at a directory inside %LOCALAPPDATA% in Windows.
For example, the root directory of Ubuntu 18.04 can be located in Windows here: %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs
This can be useful to check if the right module from the right location is being imported. It is also useful to know where to go check out the Python source files of a module for inspection or debugging.
It is useful to be able to autocomplete a path to a directory or filename while typing code or script files. This helps in ensuring that there are no mistakes and the path is correct. Thankfully, Vim has an autocompletion feature for typing path in insert mode! It calls this feature as file name completion.
Ctrl-x Ctrl-f: This is the shortcut to autocomplete path in insert mode. Start typing a path (absolute or relative) and use this keyboard shortcut. You will see a dropdown menu filled with the next entries from the filesystem that can be used to fill the path.
Ctrl-n or Ctrl-p: Shortcuts to move up and down the entries in the autocomplete dropdown menu. If you move off the top or bottom of the dropdown menu, you get the empty entry.
Absolute path: Any path that you begin typing with a slash is autocompleted as an absolute path.
Relative path: This is any path that does not begin with a slash. They are autocompleted too. Note that they will use the directory that Vim was launched from (PWD) as the root.
Hidden files or directories: I found that this was autocompleted only if I typed the first period and then used Ctrl-x Ctrl-f.
Using sudo is a common, safe and recommended method to execute commands that require superuser privileges. However, this command resets the PATH environment variable. So, some badly written installation scripts that require a particular PATH will fail in strange ways when run as sudo.
Here is some useful information about sudo and the PATH environment variable:
To ensure safety, sudo by default does not use the PATH environment variable of the user or that of root.
sudo also ignores the system-wide environment variables set in /etc/environment or in /etc/profile.d/*.sh.
The PATH variable for sudo is hardcoded to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
If you really want sudo to pick up the system-wide PATH or other environment variables, then try this:
Set the PATH or environment variable in a new file named /etc/profile.d/name_anything.sh using export
Start root shell using sudo su -
Check if your path is correct: echo $PATH
Run the command that requires superuser privilege.
If the environment variable with many values already exists and you want to prepend or append a value to it, the technique is the same. For example, to prepend to PATH:
set -x PATH /home/joe/bin/some_foo_dir $PATH
Three special environment variables: PATH, CDPATH and MANPATH are treated differently by Fish. These arrive from the environment to Fish as colon-separated, they are converted to array so we can set them easily as shown above using space-delimiter and then they are sent back to the environment as colon-separated. This logic can be seen in the Fish source code file src/env.cpphere. This is also explained in this issue.
The problem now is that there are many other environment variables which need to be colon-delimited, but Fish does not do that. For example, the dynamic linker ld.so that is used to load up DLLs when a binary executes requires LD_LIBRARY_PATH environment variable to be colon-delimited. I got errors when this variable was set using space-delimiters: cannot open shared object file: No such file or directory
If you run into any problems with an environment variable that takes a series of values, then check back to see how it is set in traditional shells like Bash. If it is colon-delimited there, then you might need to make it colon-delimited in Fish too. But, do remember to enclose it in double quotes for variable expansion to work correctly. For example:
set -x FOO_ENV_VAR "/home/joe/bin/some_foo_dir:$FOO_ENV_VAR"
Autojump can be installed and used with Fish shell as described here. However, if you source your Fish config file repeatedly, then the autojump path appears repeated in your PATH environment variable:
The installation tries to compile a few C++ files and it failed on the very first file with this error:
In file included from src/cpp/cuda.cpp:1:0:
src/cpp/cuda.hpp:14:18: fatal error: cuda.h: No such file or directory
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
This error was strange because I had set CUDA_ROOT and had added the bin path of CUDA installation to PATH environment variable. So, the installer should have found cuda.h which I could see was present in $CUDA_ROOT/include
To see what was happening, I tried the same command with verbosity:
$ sudo pip -vvv install pycuda
Now I could see that it was failing to find nvcc.
On downloading the source code of PyCUDA and checking setup.py, I saw that the check for nvcc was used to figure out the CUDA_ROOT and CUDA_INC_DIR.
The reason nvcc was not visible was that CUDA_ROOT was set for my user, but this PATH is not visible when a command is run under sudo, as described here. The solution was to make the CUDA bin path visible to sudo.
To make the $CUDA_ROOT/bin available in PATH for sudo, we can follow the steps described here. For example, on my system with CUDA 7.0 I followed these steps:
Created a new file /etc/profile.d/cuda.sh and added this line:
Opened root shell without resetting PATH and ran the pip installation:
$ sudo su -
$ pip install pycuda
This worked and PyCUDA was installed successfully! 🙂
Tried with: PyCUDA 2015.1.2, CUDA 7.0 and Ubuntu 14.04
This post shows how to quickly view the full path of the currently open file in Vim.
Some of you might like have the full path of file always be shown in the statusline. To do this set the %F item in the statusline. For example:
set statusline += '%F'
If you are using the vim-airline plugin, you can display the full path in its statusline by replacing the %f in its g:airline_section_c variable with %F. This post shows how you can view the current value of this variable.