Repository navigation
Description
Using get-pip.py to install pip in a PyPy 3.6 v7.3.0 installation from within pytest running in a macOS Python 3 virtualenv fails to install pip in the expected location (pypy3.6-v7.3.0-osx64/bin/pip), but instead installs it in the outer Python 3 virtualenv.
The following script manages to reproduce this on a mac I have access to.
mkdir tmp_dir
cd tmp_dir
curl -L https://bitbucket.org/pypy/pypy/downloads/pypy2.7-v7.3.0-osx64.tar.bz2 | tar xj
curl -L https://bitbucket.org/pypy/pypy/downloads/pypy3.6-v7.3.0-osx64.tar.bz2 | tar xj
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 -m virtualenv --version
python3 -m virtualenv env
source env/bin/activate
pip install pytest
cat << EOF > test.py
import os
import subprocess
def test2():
subprocess.check_call(['pypy2.7-v7.3.0-osx64/bin/pypy', 'get-pip.py', '-v'])
subprocess.check_call(['pypy2.7-v7.3.0-osx64/bin/pypy', '-m', 'site'])
print(os.listdir('pypy2.7-v7.3.0-osx64/bin'))
assert False
def test3():
subprocess.check_call(['pypy3.6-v7.3.0-osx64/bin/pypy3', 'get-pip.py', '-v'])
subprocess.check_call(['pypy3.6-v7.3.0-osx64/bin/pypy3', '-m', 'site'])
print(os.listdir('pypy3.6-v7.3.0-osx64/bin'))
assert False
EOF
pytest test.py
Output
ai31:~ yannick$ ./minimal_example.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 20.5M 100 20.5M 0 0 1263k 0 0:00:16 0:00:16 --:--:-- 1707k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 20.2M 100 20.2M 0 0 1406k 0 0:00:14 0:00:14 --:--:-- 1607k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1764k 100 1764k 0 0 6561k 0 --:--:-- --:--:-- --:--:-- 6561k
virtualenv 20.0.5 from /usr/local/lib/python3.7/site-packages/virtualenv/__init__.py
created virtual environment CPython3.7.5.final.0-64 in 199ms
creator CPython3Posix(dest=/Users/yannick/tmp_dir/env, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/Users/yannick/Library/Application Support/virtualenv/seed-v1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Collecting pytest
Using cached pytest-5.3.5-py3-none-any.whl (235 kB)
Collecting packaging
Using cached packaging-20.1-py2.py3-none-any.whl (36 kB)
Collecting importlib-metadata>=0.12; python_version < "3.8"
Using cached importlib_metadata-1.5.0-py2.py3-none-any.whl (30 kB)
Collecting more-itertools>=4.0.0
Using cached more_itertools-8.2.0-py3-none-any.whl (43 kB)
Collecting py>=1.5.0
Using cached py-1.8.1-py2.py3-none-any.whl (83 kB)
Collecting pluggy<1.0,>=0.12
Using cached pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting attrs>=17.4.0
Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting wcwidth
Using cached wcwidth-0.1.8-py2.py3-none-any.whl (17 kB)
Collecting pyparsing>=2.0.2
Using cached pyparsing-2.4.6-py2.py3-none-any.whl (67 kB)
Collecting six
Using cached six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting zipp>=0.5
Using cached zipp-3.0.0-py3-none-any.whl (4.8 kB)
Installing collected packages: pyparsing, six, packaging, zipp, importlib-metadata, more-itertools, py, pluggy, attrs, wcwidth, pytest
Successfully installed attrs-19.3.0 importlib-metadata-1.5.0 more-itertools-8.2.0 packaging-20.1 pluggy-0.13.1 py-1.8.1 pyparsing-2.4.6 pytest-5.3.5 six-1.14.0 wcwidth-0.1.8 zipp-3.0.0
======================================== test session starts ========================================
platform darwin -- Python 3.7.5, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /Users/yannick/tmp_dir
collected 2 items
test.py FF [100%]
============================================= FAILURES ==============================================
_______________________________________________ test2 _______________________________________________
def test2():
subprocess.check_call(['pypy2.7-v7.3.0-osx64/bin/pypy', 'get-pip.py', '-v'])
subprocess.check_call(['pypy2.7-v7.3.0-osx64/bin/pypy', '-m', 'site'])
print(os.listdir('pypy2.7-v7.3.0-osx64/bin'))
> assert False
E assert False
test.py:8: AssertionError
--------------------------------------- Captured stdout call ----------------------------------------
Non-user install because site-packages writeable
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-ephem-wheel-cache-Dzm69W
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-4kc17d
Initialized build tracking at /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-4kc17d
Created build tracker: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-4kc17d
Entered build tracker: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-4kc17d
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-install-yhafaR
1 location(s) to search for versions of pip:
* https://pypi.org/simple/pip/
Fetching project page and analyzing links: https://pypi.org/simple/pip/
Getting page https://pypi.org/simple/pip/
Found index url https://pypi.org/simple
Looking up "https://pypi.org/simple/pip/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/pip/ HTTP/1.1" 304 0
Found link https://files.pythonhosted.org/packages/3d/9d/1e313763bdfb6a48977b65829c6ce2a43eaae29ea2f907c8bbef024a7219/pip-0.2.tar.gz#sha256=88bb8d029e1bf4acd0e04d300104b7440086f94cc1ce1c5c3c31e3293aee1f81 (from https://pypi.org/simple/pip/), version: 0.2
...
Installing collected packages: pip, setuptools, wheel
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-unpacked-wheel-xnir60
changing mode of /Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/bin/pip to 755
changing mode of /Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/bin/pip2 to 755
changing mode of /Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/bin/pip2.7 to 755
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-unpacked-wheel-qGsleO
changing mode of /Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/bin/easy_install to 755
changing mode of /Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/bin/easy_install-2.7 to 755
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-unpacked-wheel-erEv1A
changing mode of /Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/bin/wheel to 755
Successfully installed pip-20.0.2 setuptools-44.0.0 wheel-0.34.2
Cleaning up...
Removed build tracker: '/private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-4kc17d'
sys.path = [
'/Users/yannick/tmp_dir',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib_pypy/__extensions__',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib_pypy',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib-python/2.7',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib-python/2.7/lib-tk',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib-python/2.7/plat-darwin',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib-python/2.7/plat-mac',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/lib-python/2.7/plat-mac/lib-scriptpackages',
'/Users/yannick/tmp_dir/pypy2.7-v7.3.0-osx64/site-packages',
]
USER_BASE: '/Users/yannick/.local' (doesn't exist)
USER_SITE: '/Users/yannick/.local/lib/pypy2.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
['libpypy-c.dylib', 'pip2', 'easy_install', 'wheel', 'pip', 'pypy', 'easy_install-2.7', 'pip2.7']
--------------------------------------- Captured stderr call ----------------------------------------
DEPRECATION: A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
_______________________________________________ test3 _______________________________________________
def test3():
subprocess.check_call(['pypy3.6-v7.3.0-osx64/bin/pypy3', 'get-pip.py', '-v'])
subprocess.check_call(['pypy3.6-v7.3.0-osx64/bin/pypy3', '-m', 'site'])
print(os.listdir('pypy3.6-v7.3.0-osx64/bin'))
> assert False
E assert False
test.py:14: AssertionError
--------------------------------------- Captured stdout call ----------------------------------------
Non-user install because user site-packages disabled
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-ephem-wheel-cache-p_j2cq6p
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-na7rsa2b
Initialized build tracking at /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-na7rsa2b
Created build tracker: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-na7rsa2b
Entered build tracker: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-na7rsa2b
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-install-08qoikav
1 location(s) to search for versions of pip:
* https://pypi.org/simple/pip/
Fetching project page and analyzing links: https://pypi.org/simple/pip/
Getting page https://pypi.org/simple/pip/
Found index url https://pypi.org/simple
Looking up "https://pypi.org/simple/pip/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/pip/ HTTP/1.1" 304 0
Found link https://files.pythonhosted.org/packages/3d/9d/1e313763bdfb6a48977b65829c6ce2a43eaae29ea2f907c8bbef024a7219/pip-0.2.tar.gz#sha256=88bb8d029e1bf4acd0e04d300104b7440086f94cc1ce1c5c3c31e3293aee1f81 (from https://pypi.org/simple/pip/), version: 0.2
...
Installing collected packages: pip, setuptools, wheel
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-unpacked-wheel-_wruh4x9
changing mode of /Users/yannick/tmp_dir/env/bin/pip to 755
changing mode of /Users/yannick/tmp_dir/env/bin/pip3 to 755
changing mode of /Users/yannick/tmp_dir/env/bin/pip3.6 to 755
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-unpacked-wheel-15knx9f1
changing mode of /Users/yannick/tmp_dir/env/bin/easy_install to 755
changing mode of /Users/yannick/tmp_dir/env/bin/easy_install-3.6 to 755
Created temporary directory: /private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-unpacked-wheel-n8_gcseu
changing mode of /Users/yannick/tmp_dir/env/bin/wheel to 755
Successfully installed pip-20.0.2 setuptools-45.2.0 wheel-0.34.2
Cleaning up...
Removed build tracker: '/private/var/folders/2k/7lc28xfj6vbfpyjpphcvyh7w0000gn/T/pip-req-tracker-na7rsa2b'
sys.path = [
'/Users/yannick/tmp_dir',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib_pypy/__extensions__',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib_pypy',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/lib-tk',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-darwin',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-mac',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-mac/lib-scriptpackages',
'/Users/yannick/tmp_dir/env/site-packages',
]
USER_BASE: '/Users/yannick/.local' (doesn't exist)
USER_SITE: '/Users/yannick/.local/lib/pypy3.6/site-packages' (doesn't exist)
ENABLE_USER_SITE: False
['libpypy3-c.dylib', 'pypy3']
======================================== 2 failed in 23.66s =========================================
I think the main thing to notice in that whole output, is that when running PyPy 3.6, v7.3.0 from within pytest from within a virtualenv, -m site gives this output:
sys.path = [
'/Users/yannick/tmp_dir',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib_pypy/__extensions__',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib_pypy',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/lib-tk',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-darwin',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-mac',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-mac/lib-scriptpackages',
'/Users/yannick/tmp_dir/env/site-packages',
]
USER_BASE: '/Users/yannick/.local' (doesn't exist)
USER_SITE: '/Users/yannick/.local/lib/pypy3.6/site-packages' (doesn't exist)
ENABLE_USER_SITE: False
while if I afterwards run the same command outside of pytest, I get:
ai31:~ yannick$ cd tmp_dir/
ai31:tmp_dir yannick$ source env/bin/activate
(env) ai31:tmp_dir yannick$ pypy3.6-v7.3.0-osx64/bin/pypy3 -m site
sys.path = [
'/Users/yannick/tmp_dir',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib_pypy/__extensions__',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib_pypy',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/lib-tk',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-darwin',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-mac',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/lib-python/3/plat-mac/lib-scriptpackages',
'/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/site-packages',
]
USER_BASE: '/Users/yannick/.local' (doesn't exist)
USER_SITE: '/Users/yannick/.local/lib/pypy3.6/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
Things to note:
- PyPy 2.7 works, PyPy 3.6 not
- virtualenv 19 works, virtualenv 20 not
- Directly running
get-pip.pyworks, running through pytest not
I have not yet tried (but will, now):
- Whether this also fails on Linux.
- Whether this also fails in a Python 2 virtualenv on macOS.
- Whether this also fails when installing a different script than
pipwithget-pip.py.
I'll tell the PyPy people on IRC, as well.
PS: I'm really sorry for finding such a nasty bug :-/ This seems horrible to debug.
EDIT: First noticed in the context of pypa/cibuildwheel#274 and #1561.
Activity
YannickJadoul commentedon Feb 22, 2020
Oh, worth noticing: is this maybe linked to #1652? That issue is about
siteas well, but for PyPy 2.7, so it's not clear.gaborbernat commentedon Feb 22, 2020
Did you try to see if using the venv instead of virtualenv gives you the same behaviour?
gaborbernat commentedon Feb 22, 2020
We don't patch site.py for Python 3 so the issue is not related.
YannickJadoul commentedon Feb 22, 2020
OK, will try that as well!
I've also just noticed I ran
python -v get-pip.pyinstead ofpython get-pip.py -v. I've changed the output of the command, above!YannickJadoul commentedon Feb 22, 2020
Tried out some more things:
pypy3 -m siteis the same inside of a pytest test as outside of it.siteis correct, so it's linked to Python 3 on macOS.ensurepipinstead ofget-pip.pyalso fails;pipis installed in the wrong location, in the CPython 3 virtualenv, rather than PyPy'sbindirectory.pipoutside of the pytest test installspipin the rightpypydirectory, but using it to install another Python package with script (e.g.,cibuildwheel) fails, as this installedpipcannot be found (pypy3 -m sitedoes not show/Users/yannick/tmp_dir/pypy3.6-v7.3.0-osx64/site-packagesto be insys.path, but suddenly/Users/yannick/tmp_dir/env/site-packagesis not insys.pathanymore, either!?)venvinstead ofvirtualenvseems to result in the exact same error. Does this meanvirtualenvis not to blame, but PyPy/pytest is to blame? But if so, isn't it weird that virtualenv 19 does work?gaborbernat commentedon Feb 22, 2020
@YannickJadoul if that's the case please open an issue at https://foss.heptapod.net/pypy/pypy/issues; the problem is upstream not within virtualenv.
YannickJadoul commentedon Feb 22, 2020
OK, even weirder: running
pypy3 -m sitegives different output before and after installingpipfrom within the pytest test:YannickJadoul commentedon Feb 22, 2020
OK, will do. Sorry for the inconvenience! :-/
gaborbernat commentedon Feb 22, 2020
Pre virtualenv 20 we used the python 2 methodologies to create virtual environments, even on python 3; which worked but caused a lot of maintainability issues and was more of a hack rather than a clean supported implementation. With virtualenv 20 we're using the same methodology as upstream does; and as described in https://www.python.org/dev/peps/pep-0405/. This explains why things worked with older virtual environments. Please link here the upstream issue once you open it so people running into the same can find it. Thanks!
PS. If upstream detect the issue and is something that can be fixed within virtualenv, please make a comment here and we'll reopen the issue and make it happen.
YannickJadoul commentedon Feb 22, 2020
Thanks, @gaborbernat! That makes sense indeed :-)
Issue reported here: https://foss.heptapod.net/pypy/pypy/issues/3175
YannickJadoul commentedon Feb 27, 2020
@gaborbernat In case you're curious: I dug deeper, and found the source of the issue. It's related to
__PYVENV_LAUNCHER__being used to determinesys.prefixinsite.py: https://foss.heptapod.net/pypy/pypy/issues/3175#note_52025Since you probably have a lot of experience dealing with these sorts of things, I'd assume that if you have time, any input or advice from you is welcome!