Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'zipimport.zipimporter' object attribute 'load_module' is read-only #1715

Closed
Ch3LL opened this issue Mar 11, 2020 · 2 comments · Fixed by #1727
Closed

AttributeError: 'zipimport.zipimporter' object attribute 'load_module' is read-only #1715

Ch3LL opened this issue Mar 11, 2020 · 2 comments · Fixed by #1727
Labels

Comments

@Ch3LL
Copy link

Ch3LL commented Mar 11, 2020

Issue

When attempting to import setuptools from an egg in a virtualenv environment I am seeing this error:

>>> import setuptools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/test/setuptools-42.0.0/setuptools-42.0.0-py3.6.egg/setuptools/__init__.py", line 20, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "/tmp/salt-tests-tmpdir/tmp8v5ucrk2/psetuptools/lib/python3.6/site-packages/_virtualenv.py", line 64, in find_spec
    setattr(spec.loader, func_name, partial(func, old))
AttributeError: 'zipimport.zipimporter' object attribute 'load_module' is read-only

Steps to reproduce:

  1. Create virtualenv and activate virtualenv
 ch3ll@thecakeisalie  /tmp  virtualenv issue-20.0.10
created virtual environment CPython3.7.5.final.0-64 in 103ms
  creator CPython3Posix(dest=/tmp/issue-20.0.10, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/ch3ll/.local/share/virtualenv/seed-app-data/v1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
 ✘ ch3ll@thecakeisalie  /tmp  source issue-20.0.10/bin/activate
(issue-20.0.10)  ch3ll@thecakeisalie  /tmp  
  1. Create an egg build of setuptools.

a) wget https://pypi.io/packages/source/s/setuptools/setuptools-42.0.0.zip
b) unzip setuptools-42.0.0.zip
c) cd setuptools-42.0.0
d) python setup.py -q bdist_egg --dist-dir .

  1. Try to import setuptools with egg in sys.path
(issue-20.0.10)  ch3ll@thecakeisalie  /tmp/setuptools-42.0.0  python -c "import sys; sys.path.insert(0, '/tmp/setuptools-42.0.0/setuptools-42.0.0-py3.7.egg'); import setuptools"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/tmp/setuptools-42.0.0/setuptools-42.0.0-py3.7.egg/setuptools/__init__.py", line 20, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 963, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 906, in _find_spec
  File "/tmp/issue-20.0.10/lib/python3.7/site-packages/_virtualenv.py", line 64, in find_spec
    setattr(spec.loader, func_name, partial(func, old))
AttributeError: 'zipimport.zipimporter' object attribute 'load_module' is read-only

And when on virtualenv 16.4.3 it works just fine:

(issue-16.4.3)  ch3ll@thecakeisalie  /tmp  python -c "import sys; sys.path.insert(0, '/tmp/setuptools-42.0.0/setuptools-42.0.0-py3.7.egg'); import setuptools"     
(issue-16.4.3)  ch3ll@thecakeisalie  /tmp  

Environment

Provide at least:

  • OS: confirmed on both macosx and manjaro.
 ch3ll@thecakeisalie  ~/git/virtualenv  ➦ 93cf9ed <B>  pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
appdirs (1.4.3)
certifi (2019.11.28)
chardet (3.0.4)
colorlog (3.2.0)
distlib (0.3.0)
filelock (3.0.12)
idna (2.8)
importlib-metadata (1.5.0)
nox-py2 (2019.6.25)
pip (9.0.3)
py (1.8.1)
pyprof2calltree (1.4.4)
pyzmq (18.1.1)
requests (2.23.0)
setuptools (41.2.0)
six (1.14.0)
tornado (4.5.3)
urllib3 (1.25.7)
virtualenv (20.0.10)
zipp (3.1.0)
You are using pip version 9.0.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
@Ch3LL Ch3LL added the bug label Mar 11, 2020
@gaborbernat
Copy link
Contributor

I'm pretty sure egg builds are not supported by setuptools, that being said I agree we should not be failing here.

@gaborbernat
Copy link
Contributor

Hello, a fix for this issue has been released via virtualenv 20.0.11; see https://pypi.org/project/virtualenv/20.0.11/ (https://virtualenv.pypa.io/en/latest/changelog.html#v20-0-11-2020-03-18). Please give a try and report back if your issue has not been addressed; if not, please comment here, and we'll reopen the ticket. We want to apologize for the inconvenience this has caused you and say thanks for having patience while we resolve the unexpected bugs with this new major release.
thanks

@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants