-
Notifications
You must be signed in to change notification settings - Fork 3k
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
After pip 10 upgrade on pyenv "ImportError: cannot import name 'main'" #5240
Comments
Hey @KleinerNull!
I think that this is an environment issue. I suggest you open an issue over at pyenv as I think the folks there would be in a better position to comment on this/fix it. |
I opened a issue at the pyenv repo. |
We are suffering from this one as well, it's broken our pipeline. Operation being run:
Ubuntu 16.04 |
We are encountering the same trouble.
|
Same here .. Exact same output as @HayaoSuzuki and we don't use pyenv |
If you're getting this outside of pyenv I suspect it's more likely to be related to #5221 |
Just to mention that |
Interestingly easy installing pip installs 10.0.0 but does not exhibit the issue
|
which is not surprising, since that pip is egg-installed in a different place thus no longer affecting the global pip - it also means you now have a very interesting workingset for python |
While I appreciate that the underlying issue reported here and in #5221 is the environment, the cause is primarily that the import |
This comment gives some informations about not to do this, but I am not entirely sure if this is also important for the pip script itself. However, it solved the problem for me. |
@davidjlloyd Because Rather than keep explaining to people that they shouldn't do this, and continually dealing with the fact that people are assuming "if I can find a function to call, it's supported" we moved everything to the The bulk of the complaints have come from people using |
I can also confirm that this issue is absolutely destroying my previously very stable process of a building a docker image, here are example minimal things I'm doing inside my docker image build process:
|
Fix for us was pinning to pip 9.03, so:
instead of
obvious fix but in case it helps somebody else! |
@peteflorence So presumably when running docker, you're creating a base image, then running I appreciate that this is a problem for you - it seems to be common for docker builds to be more inclined to do stuff as root than if you were in a normal OS (probably because a docker image is isolated). But it's still not a good idea to do this. The problem is that pip doesn't manage What you could do is switch from using |
Pinning to pip 9 is also a solution, but this begs the question, why upgrade your OS pip at all if pip 9 is OK? Does your vendor not offer a packaged version of pip 9? |
I'm not sure that aggressively breaking existing uses of an unsupported feature instead of deprecating the feature for a couple of major releases is the best approach. Our initial reaction was to pin pip back to 9.0.3, and more lazy developers would probably just call it a day at that point. This would leave a lot of users stubbornly clinging to old releases, which I doubt anyone wants. However your motivation makes sense, and the eventual result is the same. For any users hitting this issue, I think the nicest solution for replacing system or pyenv installations was kindly provided by @standag here: #5221 (comment) This solution should work for anyone building in Docker such as @peteflorence without pinning to stale releases or anything horrible like that. |
Temporary Fix upgrade pip using.
Instead of For pip2 |
I upgraded with pyenv, both python2 and python3, now pip2 not work and pip3 works pip2 pip3 After substitute pip2 import line with pip3 version, it works |
Having the same issue, heh. |
Same issue, but solved with solution: #5240 (comment) |
Same issue:
Now it's weird, it installs pip 10 to /usr/local/bin, and that is first in the PATH before /usr/bin, but it doesn't use it, not until you go to a new shell. I saw this happen when I went to this box to try to install a newer awscli by hand...
|
Yep, I think that seems to be the root of the issue, and happens across all different platforms mentioned in this thread, including Windows. In case this helps anyone else, I can confirm that switching
to:
does fix the issue. Now to update several more repos! |
I encountered the same symptom discussed here in a different situation. I was trying to use a locally installed pip, on a Ubuntu 16.0.4 system: curl -O https://bootstrap.pypa.io/get-pip.py
export PYTHONUSERBASE=$(pwd)
python ./get-pip.py --user
export PYTHONPATH=$(pwd)/lib/python2.7/site-packages
python ./bin/pip --version
Traceback (most recent call last):
File "/path/to/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named _internal It turned out that Ubuntu prepends a pip-specific path to import sys
print(sys.path)
['', '/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg', '/path/to/lib/python2.7/site-packages`, ...] I tried avoiding the prepend with
and it worked: python -S ./bin/pip --version
pip 10.0.1 from path/to/bin/pip (python 2.7) |
Sharing in case this might help others - In my docker image (base is
I changed |
Installing with --user will leave the old pip.exe script in the $PATH, but running this will fail because pip 10 moved 'main' to internal modules. pypa/pip#5240 (comment)
I'm not sure if I saw an answer / response to @davidjlloyd's comment:
Can I please ask why there was not a deprecation process in place for this? Is there a process in place to try and ensure this kind of thing is hopefully avoided in the future? |
It's been answered repeatedly, Maybe not on this specific issue, but a search of the issue tracker should find plenty of discussion on the matter.
Because it was never supported. Why would we warn that we're desupporting something we never supported? People assumed it was OK to read pip's source code and use functions they found in there in their own code. It never was. We said it could break, and in pip 10 it did.
I'm not sure it's as easy as you think. And I say that from the perspective of someone who has had to deal with issues where warnings added in pip 10 were being triggered when we hadn't expected them to be... And again, there's no need to deprecate something that's not supported in the first place.
What sort of thing? Breakage caused by us changing things that we don't guarantee backward compatibility for? No. There's no need for us to avoid that. Although in fact, we do try to manage the process, as a courtesy to our users (not an obligation!). In this case, we publicised the change 6 months in advance, offered suggestions for people who needed to change their code, and have been spending a lot of time since the release helping users who have had problems because software they rely on hasn't heeded those warnings. That's a lot of work that a very small volunteer group put into trying to mitigate a situation caused by people expecting support that was never offered or promised. You're welcome. We do have processes (deprecation warnings, etc) in place for changing things that we do guarantee compatibility for - but importing pip into your own program isn't one of them. |
I had a bash script that installed flask and requests the upgrade broke my script, but I do understand the reasons stated above. My work around to keep my script working was to simply launch a new bash process, maybe that is wrong but it worked for me. Hopefully it might help others with similar scripts.
|
@OneLogicalMyth what you are looking for may be |
completely missed that even after reading it carefully, thank you @austinbutler this has resolved my issue. |
The only reason this issue was kept open and not closed as a duplicate immediately was because I was concerned if pyenv does something with shims and if pip would need to help out in some way. That wasn't the case so, this issue is closed now. I've listed the workarounds before (all of them trivial) for almost all the these problems mentioned here - take a look at #5221 (comment). Hopefully, that addresses all the concerns raised in this issue. If it doesn't, please open a new issue. @benoit-pierre I added your suggestion of using
Thanks for clarifying my position @pfmoore. That's what I was talking about.
Me too. Just some general tips (take it or leave it), about things I saw in this issue:
To summarize, this is likely not a single project/person's fault and everyone is well reasoned for taking their actions. Yes, your environment broke. We understand. Do not throw blame at people who're volunteering their free time, to help you out right now and to develop pip. Want to help us? https://donate.pypi.org is a thing and if not that's not your type of thing, there's lot of open issues in this very issue tracker that you can help us out with. I'm gonna step back from this issue now. |
Okay, one last thing, if someone still wants to discuss regarding our decision to move all of our codebase to |
For the time being, this worked on python3 -m pip install --user --upgrade pip==9.0.3 |
@freckletonj Please do not tell people to revert to pip 9. That is not how you should resolve this issue. There are much better ways. I have linked to a comment just above yours, listing out ways to resolve this issue. |
sorry @pradyunsg , but that still doesn't work: $ pip3 install --upgrade --user pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Successfully uninstalled pip-9.0.3
Successfully installed pip-10.0.1
$ pip3
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
ImportError: cannot import name 'main' |
From #5221 (comment), which I've linked to above:
|
If anyone has any other queries, please open a new issue. |
This reportedly works around pypa/pip#5240
This reportedly works around pypa/pip#5240
#5599 provides information and provides a single location to seek help toward resolving this issue for end users. The comments section of that issue are open for users to discuss specific problems and solutions. :) |
echo "pip3 install --upgrade pip" would not upgrade pip, removing echo and quotations
Maintainer note: Anyone that still gets this issue please see #5599.
Description:
After upgrading pip from 9.03 to 10.0 via
pip install pip --user --upgrade
in a pyenv environment pip refueses to start and raise this instead:The content of all three different pip files is the same:
The same happend with my 3.6.1 environment too.
Temporaly fix
According to the code of the master branch the import should be that:
And this resolves the issue. I have no clue if this has something to do with the upgrade itself or with pyenv as environment.
The text was updated successfully, but these errors were encountered: