25

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.

41

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
  • 1
    Sure you want to cd to a file? looks like cd /mnt/e/username/folder1/folder2/ makes more sense – dufte Sep 30 '16 at 5:58
  • @dufte Good catch. Yay for copy-paste! – Kaz Wolfe Sep 30 '16 at 5:59
  • for ubuntu 16.04, it is inside of /media folder – solfish Aug 5 '17 at 20:20
7

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.

Reference

1
4

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.

3

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() { cd `wslpath "$1"`; }

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.

1
  • 2
    Wow. Usually when I see a question this old with 5 answers already, and a new user comes along with an answer, it's pretty bad. But not this time! Bravo for providing an answer that actually contributes something useful that was not covered in the others! – NotTheDr01ds Apr 25 at 2:44
0

You can try doing this : cd E:/username/folder1/folder2/ and then run python python.py. It always works in my case on Windows machine running bash.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.