How do I fix this? I was trying to upgrade my Python to 3.10.2 which works fine. However, pip
is throwing errors.
These are the steps I followed to upgrade:
#Downloaded new version and Extracted source files
wget https://www.python.org/ftp/python/3.10.2/
#Ran the configuration command
./configure --enable-optimizations
#Installed any missing dependencies
sudo apt update
sudo apt install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev
#Compiled Python
sudo make altinstall
#Link the python to new version
cd /usr/bin
sudo rm python3
sudo ln -s /usr/local/bin/python3.10 python3
Upgrade to Python 3.10.2 worked:
pi@raspberrypi:~ $ python3 --version
Python 3.10.2
pi@raspberrypi:~ $ which python3
/usr/bin/python3
pi@raspberrypi:~ $ which python
/usr/bin/python
pi@raspberrypi:~ $ python --version
Python 2.7.13
Now when trying to run pip
I get errors:
pi@raspberrypi:~ $ pip3 list
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Package Version
---------- -------
pip 21.2.4
setuptools 58.1.0
pi@raspberrypi:~ $ python3 -m pip --version
pip 21.2.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
pi@raspberrypi:~ $ python3 -m pip list
Package Version
---------- -------
pip 21.2.4
setuptools 58.1.0
Traceback (most recent call last):
File "/usr/local/lib/python3.10/runpy.py", line 196
Error when trying to upgrade pip
:
pi@raspberrypi:/usr/local/lib/python3.10/site-packages $ python -m pip install --upgrade pip
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/usr/lib/python2.7/runpy.py", line 111, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "pip/__init__.py", line 6
def main(args: Optional[List[str]] = None) -> int:
^
SyntaxError: invalid syntax
NB: I've had this Raspberry Pi for a while and never updated the OS. It has Raspbian GNU/Linux 9 (stretch).
python -m pip ...
as suggested?