I am a super newbie for Ubuntu and basically need Ubuntu for a Python package.
I would like to run a Python file in say e:/username/folder1/folder2/python.py. I tried every method online and the only reply is bash: cd./e: No such file or directory. I am not sure whether it is because of the bash windows or virtualenv.
When I use bash on Ubuntu on Windows, ls, it says VIRTUALENV_DIR. cd, it says /home/username. The cd .. etc changes the directory a little, but not another drive, nor the folder I would like it to find.
6 Answers
WSL stores your Windows drives in the /mnt folder, with the name of the drive as a subfolder. For example your C:\ drive will be present at /mnt/c/ for you to use.
Keeping this in mind, you can swap to your specific folder like so:
cd /mnt/e/username/folder1/folder2 3 In windows explorer, navigate to e:/username/folder1/folder2/,
type bash and press Enter in the address bar, a bash window with path in e:/username/folder1/folder2/ will appear.
This also work with command cmd.
A utility called wslpath that is shipped with both WSL and WSL2 can translate Windows paths to WSL paths (or translate WSL paths to Windows paths). For example, the command wslpath 'E:\username\folder1\folder2' gives you the path in WSL /mnt/e/username/folder1/folder2.
By using the wslpath utility, I define the following function in my ~/.bashrc to quickly cd to Windows paths.
cdw() { local d=`wslpath "$1"`; cd "$d"; }
With this user defined function, I can easily cd to E:\username\folder1\folder2 by simply typing
cdw 'E:\username\folder1\folder2'
Remember to wrap the Windows path by single quotes if it contains backslashes.
Changelog: June 11, 2022 - Improve the cdw function to make it work for space-containing paths such as C:\Program Files.
Yes, you can do that. I used shift + right click to get "Open Powershell here" whichever directory you want to bash and run 'bash' command, then run as usual enjoy. This is same as using Ubuntu bash as it uses same Python packages in the Windows Powershell after using 'bash' command.
Note: On windows 10 latest update maybe April 2018 with WSL and developers mode enabled.
You can try doing this :cd E:/username/folder1/folder2/and then runpython python.py. It always works in my case on Windows machine running bash.
with this little script you can execute every command from the directory your Powershell is currently in. It only works if the drive is already mounted to /mnt/ in the subsystem. It doesn't work with network resources.
function tux {$dl = (pwd).Path | wsl eval "cut -c 1 | tr 'A-Z' 'a-z'"; $wd = (pwd).Path | wsl eval "cut -d : -f 2 | tr '\\' '/' 2> /dev/null" ; wsl eval "cd '/mnt/$dl$wd' && eval '$args'"}after you have executed it, you can use it like this:
tux vim test.txt