I installed Python3.11 which is located usr/local/bin/python3
, which came without pip. The old Python3.10 was located in usr/bin/python3
.
I tried to install pip with sudo apt-install python3-pip
, but it seems to be attached to the old Python3.10. If I check pip --version
, the output will be this:
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
, but I need it for Python3.11. For example if I try to pip install requests
now, I get Requirements already satisfied: requests in /usr/lib/python3/dist-packages (2.25.1)
, which is the Python3.10 folder.
CodePudding user response:
Maybe you need pyenv:
What pyenv does...
- Lets you change the global Python version on a per-user basis.
- Provides support for per-project Python versions.
- Allows you to override the Python version with an environment variable.
- Searches for commands from multiple versions of Python at a time. This may be helpful to test across Python versions with tox.
I'm using it to manage my virtual environments and my global environments
❯ pyenv global 3.10.5
❯ pyenv versions
system
3.7.10
* 3.10.5 (set by /home/xunjie/.pyenv/version)
3.10.8
❯ which python
/home/xunjie/.pyenv/shims/python
❯ which pip
/home/xunjie/.pyenv/shims/pip
CodePudding user response:
Your new python version(/usr/local/bin/python3) has pip. But your symbolic links has got twisted, you couldn't use it easily. Try this below.
/usr/local/bin/python3 -m pip install pip
Also before you change your symbolic links, you have to use pip like this below.
/usr/local/bin/python3 -m pip install <package>
If you want to use new python version as python
OR python3
command,
whereis python3.11
the result will be like this. the second column is the binary (But in your case /usr/local/bin/python3).
> python3.11: /usr/local/bin/python3.11 /usr/local/share/man/man1/python3.11.1
Before changing all symbolic links to link new python3.11,
Let's find a newer pip binary
which pip3.11
the result of mine is
> /usr/local/bin/pip3.11
Let's find the old python and pip symbolic link path.
which python
which python3
which pip
which pip3
let's say the result is
which python
> /usr/bin/python
which python3
> /usr/bin/python3
which pip
> ~/.local/bin/pip
which pip3
> ~/.local/bin/pip3
Let's connect symbolic links to newer python.
ln -sf /usr/local/bin/python3.11 /usr/bin/python
ln -sf /usr/local/bin/python3.11 /usr/bin/python3
ln -sf /usr/local/bin/pip3.11 ~/.local/bin/pip
ln -sf /usr/local/bin/pip3.11 ~/.local/bin/pip3
ln -s
creates a symbolic link.
-f
option of ln
overwrites an existing symbolic link.