5

I am ssh’d into a development environment (vagrant Ubuntu box) and my project directory is mapped to another filesystem (via vbox) so symlinks are not supported. I am attempting to create a new venv, but the --copies flag isn’t being respected.

$sudo python -m venv --copies venv 
Error: [Errno 71] Protocol error: 'lib' -> '/home/vagrant/vagrant_projects/rurp/venv/lib64'

If I use python 2.7 ($virtualenv venv --always-copy) it works, but not with the python3 venv --copies implementation. The --always-copy argument was a workaround for similar issues with python2.x.

I could not find anything online indicating a bug in venv and am at a bit of a loss. Has anyone else had this issue?

$ python -V
Python 3.6.9

Thank you in advance.

Edit: Also tested in python 3.8.1.

Will
  • 97
  • 7
  • 1
    Looking at the [source code for `venv`](https://github.com/python/cpython/blob/3.8/Lib/venv/__init__.py#L420), `--copies` looks like a no-op unless you are using Windows. – chepner Feb 12 '20 at 18:04
  • It set a defualt, but shouldn't that be overridden with the [group.add_argument a few lines later](https://github.com/python/cpython/blob/3.8/Lib/venv/__init__.py#L430)? – Will Feb 12 '20 at 18:41
  • `--copies` uses `store_false` as its action, which just stores `False` in the destination, regardless of what is already there, so it's a no-op if the default is already `False`. – chepner Feb 12 '20 at 18:59
  • Thanks! Do you think that this qualifies as a bug or just a documentation issue? – Will Feb 12 '20 at 19:22

2 Answers2

3

Per @chepner's comment above, it looks like the --copies argument is ignored on non-Windows systems (no mention of this in the documentation). I was able to workaround the issue by creating the venv in a local directory, manually copying the symlinked lib64 to a real directory, moving the venv to my project folder and manually updating the activation scripts. Ugly, but it works.

$cd ~
$python3 -m venv --copies --clear venv
$cp -r --remove-destination `readlink lib64` lib64
$cp -r venv vagrant_project/rurp/

I would be happy to accept a more elegant answer.

Will
  • 97
  • 7
0

I ran into this problem on a Windows host and an Ubuntu box. No need for ugly workarounds. This github issue has the solution. Set the environment variable:

VIRTUALENV_ALWAYS_COPY=1 virtualenv /path/to/env
uKolka
  • 36,422
  • 4
  • 33
  • 44