venv not respecting –copies argument

Question:

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.

Asked By: Will

||

Answers:

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.

Answered By: Will

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
Answered By: uKolka