Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

windows - Pip reference broken for multiple python versions

I'm trying to install multiple python versions on Windows as I need a 32-bit and 64-bit version. I currently have python 3.7 32 bit installed and am trying to get python 3.9 64-bit working (although I tried this with 3.8 64-bit as well, getting me the same results).

Installing via the executable files provided via python.org does no give any issues, expect that pip doesn't seem to be installed properly. When checking the pip install via pip3.9 -V, I get 'pip3.9' is not recognized as an internal or external command, operable program or batch file. even though I have set the environment variables for this new python install.

When I check the python install, it starts to make sense that it has troubles finding pip, as it isn't installed in Python39Scripts. However, when I manually try to install pip using py -3.9 get-pip.py, I get another error:

Traceback (most recent call last):
  File "<user>get-pip.py", line 24, in <module>
    import pkgutil
  File "<user>AppDataLocalProgramsPythonPython37-32Libpkgutil.py", line 5, in <module>
    import importlib
  File "<user>AppDataLocalProgramsPythonPython37-32Libimportlib\__init__.py", line 51, in <module>
    _w_long = _bootstrap_external._w_long
AttributeError: module 'importlib._bootstrap_external' has no attribute '_w_long'

This traceback indicates that, even though I'm calling py -3.9, it is using libraries from my python 3.7 install. The same error pops up when running py -3.9 -m pip --version or py -3.9 -m ensurepip --upgrade.

Related stackoverflow questions (here and here) haven't been able to help as they seem to run into the same error in a different situation.

Any help would be appriciated!

question from:https://stackoverflow.com/questions/65941132/pip-reference-broken-for-multiple-python-versions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Installing multiple versions of python next to each other is a slippery slope in my experience. Make sure all your python versions can be found (they should be in your shell's $PATH variable). If you want to call pip that needs to be in $PATH too. All versions of it and properly configured for all the names of all the versions of python you have installed.

In my experience it is much easier to call pip as a module from python directly, which is now, for installing packages at least, the preferred way anyway.
$ python3.9 -m pip //whatever you wanna do with pip

If you want to work with different setups side by side, you should look into virtual environments. Quite easy to setup and they keep everything nice and organised.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...