pip: ImportError: cannot import name 'SourceDistribution' from 'pip._internal.distributions.source'
Environment
CircleCI using Conda, eg https://circleci.com/gh/peterjc/thapbi-pict/1073
- pip version: pip-19.2.3 (from conda) updated to 19.3 (via
pip install --upgrade pip setuptools
) - Python version: python-3.7.3
- OS: Linux
I have made only minor changes to my code, but today the CircleCI builds broke during the build/install stage of my Python tool - multiple branches affected. The timing fits the release of pip 19.3 on PyPI.
Description
It appears a recent release of pip moved some internal files about, my guess is #6830.
Expected behavior
How to Reproduce
Full output on https://circleci.com/gh/peterjc/thapbi-pict/1073 which is running https://github.com/peterjc/thapbi-pict/blob/9fcec2da60e6e6ae5cf7ee6ad4b53dcc3a40cfe7/.circleci/config.yml#L56
...
python setup.py sdist --formats=gztar
python setup.py bdist_wheel
pip install dist/thapbi_pict-*.whl
Output
Traceback (most recent call last):
File "/opt/conda/bin/pip", line 7, in <module>
from pip._internal import main
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 11, in <module>
from pip._internal.commands import (
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 9, in <module>
from pip._internal.commands.download import DownloadCommand
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/commands/download.py", line 10, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 9, in <module>
from pip._internal.distributions import (
File "/opt/conda/lib/python3.7/site-packages/pip/_internal/distributions/__init__.py", line 1, in <module>
from pip._internal.distributions.source import SourceDistribution
ImportError: cannot import name 'SourceDistribution' from 'pip._internal.distributions.source' (/opt/conda/lib/python3.7/site-packages/pip/_internal/distributions/source/__init__.py)
Exited with code 1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 60
- Comments: 101 (20 by maintainers)
Commits related to this issue
- Stick with latest pip/setuptools from conda The update to pip 19.3 broke the build, see https://github.com/pypa/pip/issues/7217 — committed to peterjc/thapbi-pict by peterjc 5 years ago
- potential fix - see https://github.com/pypa/pip/issues/7217 — committed to openworm/openworm_docs by casperdcl 5 years ago
- potential fix - see https://github.com/pypa/pip/issues/7217 — committed to openworm/openworm_docs by casperdcl 5 years ago
- try to fix again - see https://github.com/pypa/pip/issues/7217#issuecomment-542359205 — committed to openworm/openworm_docs by casperdcl 5 years ago
- Add an environment variable to bust the package See here: https://github.com/pypa/pip/issues/7217#issuecomment-543280402 Basically, an internal change was made to Pip, but because the dependencies... — committed to euantorano/docker-zig by euantorano 5 years ago
- Remove cache from verify-olm CircleCI task The current cache approach seems to have broken after some update from CircleCI side and we're getting an exception (see https://github.com/pypa/pip/issues/7... — committed to Dynatrace/dynatrace-oneagent-operator by lrgar 5 years ago
- Attempted fix for SourceDistribution error ``` ImportError: cannot import name 'SourceDistribution' ``` see: - https://github.com/pypa/pip/issues/7217 - https://latest-ci.openmicroscopy.org/jenki... — committed to joshmoore/jenkins-library-recursivemerge by joshmoore 4 years ago
- Test against latest Anki tag, not against master — committed to glutanimate/pytest-anki by glutanimate 4 years ago
- Manually install and pin pip until upstream bug fixed https://github.com/pypa/pip/issues/7217 — committed to glutanimate/pytest-anki by glutanimate 4 years ago
- fix: pip pinned to 19.3.1 after v20 breaking reference: https://github.com/pypa/pip/issues/7217 — committed to gavindsouza/bench by gavindsouza 4 years ago
- travis: pin pip version in Travis * There is a problem with latest pip version (20.0), more [here](https://github.com/pypa/pip/issues/7217). — committed to diegodelemos/reana-workflow-controller by deleted user 4 years ago
- travis: pin pip version in Travis * There is a problem with latest pip version (20.0), more [here](https://github.com/pypa/pip/issues/7217). — committed to diegodelemos/reana-server by deleted user 4 years ago
- Try fix deploy build error ImportError: cannot import name 'SourceDistribution' https://github.com/pypa/pip/issues/7217#issuecomment-542229562 — committed to vulekamali/ckan-datapusher by jbothma 4 years ago
- GitHub workflow: fix for https://github.com/pypa/pip/issues/7217 — committed to koendewit/django-direct-cloud-upload by koendewit 4 years ago
- pin pip version https://github.com/pypa/pip/issues/7217 — committed to giffon/charleywong by andyli 4 years ago
- global: pin pip version in Travis and Dockerfile * There is a problem with latest pip version (20.0), more [here](https://github.com/pypa/pip/issues/7217). — committed to diegodelemos/reana-server by deleted user 4 years ago
- global: pin pip version in Travis and Dockerfile * There is a problem with latest pip version (20.0), more [here](https://github.com/pypa/pip/issues/7217). — committed to diegodelemos/reana-workflow-controller by deleted user 4 years ago
- pip: pin to lower version https://github.com/pypa/pip/issues/7217 — committed to cloudify-cosmo/cloudify-manager by tyacbovi 4 years ago
- Re-trigger pipeline See https://github.com/pypa/pip/issues/7217 — committed to cristiklein/azure-cli by cristiklein 4 years ago
- Re-trigger pipeline See https://github.com/pypa/pip/issues/7217 — committed to cristiklein/ansible by cristiklein 4 years ago
Thanks @PabloCastellano! I’m just ignoring comments here now, since I don’t want my heartrate going any higher. 😃
Made the bugfix release. If that helped, use 👍 on this post. Otherwise, please write a comment with the error message.
Please stop reporting “me too”. @pradyunsg is working on a fix right now
This helped for now
Alrighty, pushed this now. The change should’ve propagated to bootstrap.pypa.io by now. Or it will really soon.
Okay, I have reproduced this locally – I’ll file a PR with a fix soon.
I’m now getting issues with this on the 0.20 release.
Can others seeing this failure confirm that there’s a source/ folder in pip/_internal/distributions?
If you can confirm that folder exists, don’t make comment here – use the 👍 reaction on this post. That folder does not exist, use the 👎 reaction.
Sorry everyone for the breakage, and thanks for working with us here to fix this breakage!
@xavfernandez figured out why this happened and we’ll be making changes to our release process to prevent similar failures in the future: #7624
If you use virtualenv just downgrade to 19.x. This resolved the issue in my virtualenv:
I just got this when my deployment auto-upgraded pip from 19.3.1 to 20.0
Everything is already using python -m pip - that is not the issue here
I can tell you that the fix from JediKev, that is to delete this folder:
site-packages/pip/_internal/distributions/source
fixed the problem
Are any of you guys using caching? I think it’s possible some pip internals changed and when you restore the cache of the old python version pip breaks. Suggest you invalidate your circle CI caches by changing the
keys
and see what happens … (worked for me!)Removing folder ./site-packages/pip/_internal/distributions/source helps!
Same here, all of our CI builds that update pip are failing.
XD
Replacing
pip install --upgrade pip
withpip install --upgrade pip"<20.0"
working here.pip install pip"<20.0"
temp solution but it works.😃 let us know when this will be good to go
ok let me run my build again
Hi @CharrierCoop! You should be able to download get-pip.py and install pip 20.0.1 using that.
See https://pip.pypa.io/en/stable/installing/
Agreed, fantastic turnaround on the fix here!
Can confirm.
pip==20.0.1
is working fineFor a quickfix,
also works ok
Same here with python 3.7.6 and pip 20.0
Had to select the previous version to sort out, curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py pip=19.3.1
A quick fix which is working is
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py pip==9.0.2
Saved our CI pipeline
What if I roll back to pip 19.x? Would it work?
EDIT:
pip install --upgrade "pip==19.3.1"
still works.sudo python get-pip.py pip==19.3.1"
fix this issueI think, the problem was created because there is a
source
module directory as well assource.py
in thepip/_internal/distributions
path and that messes up the importsIn
pip/_internal/distributions/__init__.py
have an import line:But there’s also a
source
dir with__init__.py
inside there,Hence that import will fail. Renaming the
source.py
to_source.py
and changing the import in__init__.py
tofrom pip._internal.distributions._source import SourceDistribution
seems to fix itNote that get-pip.py hasn’t been updated yet – that’s because, well, I borked my own dev environment for get-pip when testing this. 😃
I’ll update that in the next few minutes.
Between all the temporary workarounds, only this one worked for me
@manutero, the
--no-download
flag of thevirtualenv
command will avoid trying to download the latest version ofpip
at the time of creating the environment.All builds are broken due to the same error on our end too.
@pradyunsg any CI improvements so that it doesn’t happen in the future? A docker container would be sufficient. Would you accept PRs for this?
It should be python3 get-pip.py pip==19.3.1
@pradyunsg, on Fedora 29 I can reproduce like this:
Try this:
1.curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 2.python get-pip.py
I know my setup might be different than most but the issue on my end was due to the PIP
sources/
directory in the virtual environment (most likely PIP caching issues or something). Let me explain: When deleting theuser_builds/project/envs/
directory for a project and rebuilding it works but only until you go to rebuild with theenvs/
directory present again. I spent a ton of time debugging what the issue was and it turns out it was theuser_builds/project/envs/
directory (or something inside) causing issues. So I did more testing to figure out that it was theuser_builds/project/envs/latest/lib/python3.6/site-packages/pip/_internal/distributions/source/
directory specifically causing issues. I removed theuser_builds/project/envs/latest/lib/python3.6/site-packages/pip/_internal/distributions/source/
directory, rebuilt, and everything was fine. I rebuilt again and it failed. I checked theuser_builds/project/envs/latest/lib/python3.6/site-packages/pip/_internal/distributions/
directory again and saw thatsource/
was present. So I went to my global Python install and moved the/path/to/lib/python3.6/dist-packages/pip/_internal/distributions/source/
directory from PIP, removed theuser_builds/project/envs/latest/lib/python3.6/site-packages/pip/_internal/distributions/source/
directory from the project environment, and rebuilt. This built successfully and didn’t copy over thesource/
folder, perfect. So now any time the docs build they build without errors. I hope this helps someone else.Cheers.
I’m gonna go ahead and close this issue now, since it seems like things are working for most users.
If you’re still facing issues, please look for duplicates filed in earlier (since Jan 21, for pip 20.0) and if there are none, file a new issue.
No need this issue was fixed by @pradyunsg
I can confirm, the new
pip
gets installed now that does not suffer from this error anymore. Thanks @pradyunsg !@pradyunsg You’ve just lowered mine. Seems to work.
Yep. hitting this now worked yesterday.
Thank you
Hey people,
I really don’t know if this helps you in any way, but I got the same Error Message on my MSYS setup trying to install WeasyPrint.
After uninstalling python3-pip and python3-setuptools i deleted all pip folders in /usr/lib/python3.7/site-packages/ and reinstalled both… solved that specific error.
To be fair, I now ran into compiler issues… but maybe i could help…
I have same problem on CircleCI since 1 hours ago. Version changing of docker image from python:3.7 to python:3.7.4 fixes this issue. (just workaround) . like this:
thank you very much
No. We’re not going to be deleting it. We have a standard-backed feature for “yanking” broken releases. Once PyPI adds support for that, we’ll yank this release (if anyone cares by then).
See https://www.python.org/dev/peps/pep-0592/#motivation for more details.
Hello, I’m stuck in 20.0 All the commands that I tried return this error about ‘SourceDistribution’.
I tired to uninstall too :
Anyone have another solution to uninstall pip?
Ubuntu 18.04.3 LTS Python 3.6.9 run in virtualenv
Considering the nature of this bug, can you please remove 20.0 release from PYPA? https://pypi.org/project/pip/#history
Another question would what we could do to avoid a similar regression in the future.
Help me in docker RUN pip install --upgrade pip"<20.0"
Yep, pip 20.0 breaks , using “virtualenv .” command to create venv
Yeah, pip version 20.0 breaks
Moving to
python -m pip
helped in my situation. From https://github.com/ome/jenkins-library-recursivemerge/pull/4/filesFails:
Passes:
@Guru36
Tried that many many times with no success. You have to do this at the start anyways so this wouldn’t help. Thanks anyways though.
Cheers.
We were able to do work-around on our local ReadTheDocs server by changing the build flow to specifically use pip version 19.2.3. Now ReadTheDocs runs the following build command - and we no longer have caching issue:
More specifically, we updated the local python_environment.py file to use a specific pip version: https://github.com/readthedocs/readthedocs.org/blob/7212d6ff738b24a10fb0f4227d3fbdf69e5cab42/readthedocs/doc_builder/python_environments.py#L322
changed to:
Confirmed that removing
pip install --upgrade pip setuptools
fixed things,https://github.com/peterjc/thapbi-pict/commit/4060404c1034a676439aef1369260022577a6627 https://circleci.com/gh/peterjc/thapbi-pict/1074
i.e. Something broke in how I updated from pip 19.2.3 to 19.3
I am not intentionally using the CircleCI provided Python, rather the Conda provided Python - is there value in switching from
pip ...
topython -m pip ...
just to remove the possibility of this being due to mixing Pythons?