You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello up there. I've discovered that with python2 virtualenv 20 does not process .pth files under site-packages if $PYTHONPATH points to site-packages directory. It is a regression compared to virtualenv 16. This causes testing breakage of real projects, for example pygolong tox tests with new virtualenv become broken due to this issue.
Below is a brief demonstration for the problem:
# create virtualenv with python2 and install zope.interfaceskirr@deco:~/tmp/trashme$ virtualenv -p python2 x.venvcreated virtual environment CPython2.7.18.final.0-64 in 134ms creator CPython2Posix(dest=/home/kirr/tmp/trashme/x.venv, clear=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/kirr/.local/share/virtualenv) added seed packages: pip==20.1.1, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.35.1 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivatorkirr@deco:~/tmp/trashme$ unset PYTHONPATHkirr@deco:~/tmp/trashme$ . x.venv/bin/activate(x.venv) kirr@deco:~/tmp/trashme$ pip install zope.interfaceDEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-supportCollecting zope.interface Using cached zope.interface-5.1.1-cp27-cp27mu-manylinux2010_x86_64.whl (232 kB)Requirement already satisfied: setuptools in ./x.venv/lib/python2.7/site-packages (from zope.interface) (44.1.1)Installing collected packages: zope.interfaceSuccessfully installed zope.interface-5.1.1
# make sure `import zope.interfaces` works(x.venv) kirr@deco:~/tmp/trashme$ pythonPython 2.7.18 (default, Apr 20 2020, 20:30:41) [GCC 9.3.0] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import zope.interface>>> import zope>>> zope.__path__['/home/kirr/tmp/trashme/x.venv/lib/python2.7/site-packages/zope']
# set$PYTHONPATH to site-packages and retry importing zope.interfaces
# ->`import zope` fails(x.venv) kirr@deco:~/tmp/trashme$ PYTHONPATH=/home/kirr/tmp/trashme/x.venv/lib/python2.7/site-packages pythonPython 2.7.18 (default, Apr 20 2020, 20:30:41) [GCC 9.3.0] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import zope.interfaceTraceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named zope.interface>>> import zopeTraceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named zope
The issue happens due to below check of if full_path not in sys.path in
which, in the presence of namespace packages (packages that are only installed via .pth files, not via __init__.py) leads to ImportError for those packages. For the reference here are corresponding directory and .pth for zope.interfaces:
# the nspkg.pth file(x.venv) kirr@deco:~/tmp/trashme$ cat x.venv/lib/python2.7/site-packages/zope.interface-5.1.1-py2.7-nspkg.pth import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('zope',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('zope', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('zope', [os.path.dirname(p)])));m = m or sys.modules.setdefault('zope', types.ModuleType('zope'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
As said above this leads to pygolang tox tests failure, e.g.
I've also hit this issue by trying to spawn a subprocess with PYTHONPATH set from sys.path of the parent (to make sure the child can import everything parent could).
Issue
Hello up there. I've discovered that with python2 virtualenv 20 does not process .pth files under site-packages if $PYTHONPATH points to site-packages directory. It is a regression compared to virtualenv 16. This causes testing breakage of real projects, for example pygolong tox tests with new virtualenv become broken due to this issue.
Below is a brief demonstration for the problem:
The issue happens due to below check of
if full_path not in sys.path
invirtualenv/src/virtualenv/create/via_global_ref/builtin/python2/site.py
Lines 47 to 56 in 5e46e4a
which, in the presence of namespace packages (packages that are only installed via .pth files, not via
__init__.py
) leads to ImportError for those packages. For the reference here are corresponding directory and .pth for zope.interfaces:As said above this leads to pygolang tox tests failure, e.g.
Thanks beforehand,
Kirill
Environment
Provide at least:
Linux deco 5.8.0-2-amd64 #1 SMP Debian 5.8.10-1 (2020-09-19) x86_64 GNU/Linux
pip list
of the host python wherevirtualenv
is installed:Output of the virtual environment creation
Make sure to run the creation with
-vvv --with-traceback
:The text was updated successfully, but these errors were encountered: