22

I'm getting an error in WSL while trying to use junyanz/pytorch-CycleGAN-and-pix2pix.

I followed all the install steps successfully on Windows 10 x64 using the steps at PyTORCH on Windows 10: An instructional with screenshots, then Ubuntu for Windows with GitHub desktop How to Install and Use the Linux Bash Shell on Windows 10.

But I'm blocked at the latest steps.

It's where I trying to download or train the model in Windows. Using for example the Ubuntu Linux prompt, I navigate manually to the appropriate place and type a following command like the one below (I also tried in su mode)

bash pretrained_models/download_pix2pix_model.sh facades_label2photo

I get an immediate error, always the same, similar to these:

root@Azure:/mnt/c/Users/vincent/Downloads/vision/pytorch-CycleGAN-and-pix2pix# bash pretrained_models/download_pix2pix_model.sh facades_label2photo
pretrained_models/download_pix2pix_model.sh: line 2: $'\r': command not found
Note: available models are edges2shoes, sat2map, and facades_label2photo
pretrained_models/download_pix2pix_model.sh: line 4: $'\r': command not found
]pecified [facades_label2photo
pretrained_models/download_pix2pix_model.sh: line 6: $'\r': command not found
mkdir: cannot create directory ‘./checkpoints/facades_label2photo\r_pretrained\r’: No such file or directory
pretrained_models/download_pix2pix_model.sh: line 10: $'\r': command not found
WARNING: timestamping does nothing in combination with -O. See the manual
for details.

: No such file or directoryhphoto
pretrained_models/download_pix2pix_model.sh: line 12: $'\r': command not found
pretrained_models/download_pix2pix_model.sh: line 13: $'\r': command not found

Any idea?

  • 4
    I have no idea what you're doing, but $'\r': command not found strongly suggests the issue is that you have used a Windows text editor that has saved your files with DOS-style CRLF line endings - see for example DOS vs. Unix Line Endings – steeldriver Oct 19 '17 at 22:37
  • But Im just typing the command directly in the Window Ubuntu command prompt. Not passing by any text editor at all... – Vincent Thomas Oct 20 '17 at 12:08
  • 1
    @VincentThomas This is a text file: pretrained_models/download_pix2pix_model.sh – wjandrea Oct 27 '17 at 18:02
  • Try the answer here: How to change Windows line-ending to Unix version. If it works, let us know and we will close your question as a duplicate. – wjandrea Oct 27 '17 at 18:09
  • @wjandrea I don't think this is really a duplicate of How to change Windows line-ending to Unix version. The reasonable solution here is to run git clone within the WSL system, and not to undertake extra effort attempting to convert each file. If the goal is to install software in Ubuntu, there is no reason to download it outside its filesystem first. – Eliah Kagan Oct 27 '17 at 18:15
22

Inside WSL:

sudo apt-get install dos2unix

Then,

dos2unix [file]

Full documentation:

man dos2unix

Saved my day, hope it helps.

  • This works. I was using VSCode and had a shell script that executes some rsync and ssh command, and ran into this issue. I installed dos2unix inside WSL like Chaim said, and executed once, wsl dos2unix deploy.sh from Powershell, and now, everytime I type, wsl ./deploy.sh everything works perfectly! Thanks a lot. – Dan Zuzevich Aug 17 at 23:10
7

steeldriver is correct that the problem is that you have files with Windows line endings and bash cannot run them. $'\r' is a representation of the carriage return character (CR) that is part of traditional DOS and Windows line endings (CR LF), but which is absent in traditional Unix-style line endings (LF).

As you say, you're typing the command to attempt to run the script in bash, but notice that the script is actually stored outside your Ubuntu (WSL) system, in your Windows download directory:

/mnt/c/Users/vincent/Downloads/vision/pytorch-CycleGAN-and-pix2pix

WSL paths that start with /mnt/c, where c may be any Windows drive letter, are paths that access files and directories outside the Ubuntu system. As a Windows path, that is:

C:\Users\vincent\Downloads\vision\pytorch-CycleGAN-and-pix2pix

That a file is stored in your Windows system outside the area where Ubuntu is installed does not guarantee that it uses Windows-style instead of Unix-style line endings. However, if you downloaded the files with Git in Windows, its default configuration is to give you Windows-style line endings.

The easiest way to fix the problem is really to just download the files you need inside the Ubuntu system from your bash prompt. I recommend you fully update the Ubuntu system, then install git in Ubuntu, as well as build-essential which provides useful tools that you need to compile most software from source code. For Python programs, you may not need build-essential; you can omit it if you like, but I suspect you'll end up needing it at some point.

sudo apt update && sudo apt upgrade && sudo apt install git build-essential

Then use the cd command to go to a directory where you would like to download the software. This should be a directory within your Ubuntu system. For example, it could be your Ubuntu home directory or somewhere inside there. Once there, clone the repository from GitHub. I did it inside the src directory that I made inside my home directory.

cd ~/src
git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix.git

Of course, you will most likely have to install the dependencies first. To do that, just follow all the official instructions. Do all those steps within the Ubuntu system.

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.