Search code examples
windows-subsystem-for-linuxonedrivepython-venvrclone

Issue with creating virtual environment on wsl2 and onedrive


I'm using Windows Subsystem for Linux (WSL2), and OneDrive mounted using rclone, on a Windows 10 machine. When using WSL2 in the local directories, I can create a virtual environment for a project:

python -m venv myenv/

However, if I'm in a directory on OneDrive, and I run this command, I get an error:

Error: [Errno 5] Input/output error: 'lib' -> '/home/andrew/onedrive/myproject/venv/lib64'

If I look in the myproject directory, I can see that directory venv has been created. However it is incomplete, in that it only has 'lib' and 'include' subdirectories. When it is created properly (that is, in a directory not on OneDrive), it has 'lib, 'include', 'bin', 'lib64', 'share', and 'pyvenv.cfg'.

'lib64' is a symbolic link pointing to 'lib' in the normal installation. In the error message above, it seems that lib is actually pointing to lib64, so I suppose this is the input/output error?

Is there a way to get venv to work on OneDrive directories when mounted via rclone and using WSL2?


Solution

  • My hunch is that something in the way Rclone works is causing your issue. It purports to be "inspired by rsync", which means that it isn't really "mounting", but is "syncing" the cloud storage.

    I did a quick install of rclone in a new WSL instance, and I'm seeing the same "Input/Output error" that you experienced.

    I'm guessing that you would see the same problem even if under a "full" Linux installation. In other words, I doubt this has anything to do with the interaction between WSl and rclone. It's probably more about the interaction between Python's venv module and rclone. I don't know for sure, but I have my doubts that rclone is designed for "live" usage. It's more for being able to access (and write) files on cloud-storage providers from Linux.

    The good news is that there's likely an alternative. Windows automatically makes your OneDrive folder available in %userprofile%\OneDrive. From WSL, you can access this with:

    cd $(powershell.exe -c 'Write-Host -NoNewLine $env:userprofile' | xargs -0 wslpath)/OneDrive
    

    That's usually /mnt/c/Users/<yourusername>/OneDrive.

    From there, python3 -m venv myvenv/ worked correctly for me.

    That said, I highly recommend against doing this in WSL2, as performance of NTFS files is abysmal. Best to use a WSL1 instance if you really need to do it.