This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients Antony.Lee, vinay.sajip
Date 2017-11-21.21:51:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511301111.28.0.213398074469.issue30811@psf.upfronthosting.co.za>
In-reply-to
Content
The problem for venv is that it's tied to the running interpreter, which is (in the case you mention) the one from the outer virtualenv. Unlike virtualenv, venv does not provide a mechanism to restart itself with a different Python interpreter.

I don't know how Conda works in detail, but virtualenv makes copies of parts of the stdlib; venv, on the other hand, doesn't, but keeps a reference to its original Python environment. That is, I think, the reason for the difference in behaviour.

Instead of just using 'python' to invoke the command which runs the "-mvenv", you could get the underlying Python and create the venv using that. For example, using this script "upvenv.py":

#!/usr/bin/env python
def make_venv(venvpath):
    import os
    import subprocess
    import sysconfig

    python = os.path.join(sysconfig.get_config_var('BINDIR'), 'python3')
    cmd = [python, '-mvenv', venvpath]
    subprocess.run(cmd)

if __name__ == '__main__':
    import sys
    assert len(sys.argv) == 2
    try:
        rc = make_venv(sys.argv[1])
    except Exception as e:
        print('Failed: %s' % e)
        rc = 1
    sys.exit(rc)

I get:

vinay@ubuntu:/tmp$ cd /tmp
vinay@ubuntu:/tmp$ ve15 --version
15.1.0
vinay@ubuntu:/tmp$ ve15 -p python3 outer
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/outer/bin/python3
Also creating executable in /tmp/outer/bin/python
Installing setuptools, pip, wheel...done.
vinay@ubuntu:/tmp$ source outer/bin/activate
(outer)  vinay@ubuntu:/tmp$ python upvenv.py inner
(outer)  vinay@ubuntu:/tmp$ source inner/bin/activate
(inner)  vinay@ubuntu:/tmp$ python -minspect -d pip
Target: pip
Origin: /tmp/inner/lib/python3.5/site-packages/pip/__init__.py
Cached: /tmp/inner/lib/python3.5/site-packages/pip/__pycache__/__init__.cpython-35.pyc
Loader: <_frozen_importlib_external.SourceFileLoader object at 0x7f6917e9e860>
Submodule search path: ['/tmp/inner/lib/python3.5/site-packages/pip']

which seems OK.

This approach can't be transplanted into venv because it doesn't have the ability to restart with a different interpreter.
History
Date User Action Args
2017-11-21 21:51:51vinay.sajipsetrecipients: + vinay.sajip, Antony.Lee
2017-11-21 21:51:51vinay.sajipsetmessageid: <1511301111.28.0.213398074469.issue30811@psf.upfronthosting.co.za>
2017-11-21 21:51:51vinay.sajiplinkissue30811 messages
2017-11-21 21:51:51vinay.sajipcreate