0

I have a Raspberry Pi 3 with Raspbian and I upgraded python version from 3.7 to 3.8. If I type python --version in the terminal the correct version appears as the system version. However none of the modules that I have installed AFTER the version change seem to work. Python gives ModuleNotFoundError when trying to import ANY of the modules that I have installed.

I can see the modules with pip freeze but Python seems to not be able to find them.

I followed this instructions to purge 3.7. I reinstalled pip after purging python 3.7 but pip as again installed in /home/pi/.local/lib/python3.7/site-packages/pip. How can I get rid of 3.7 completely?

5
  • 4
    I guess you used pip from the older version to install new modules. Try comparing pip -V and python -m pip -V Commented Oct 3, 2022 at 20:13
  • i have installed python 3.8 removed everything for 3.7 then reinstalled pip but somehow it still does not work. I added a link to the instructions I followed to install python 3.8 and purge 3.7. Even after re-installing pip it was installed in this path /home/pi/.local/lib/python3.7/site-packages/pip Commented Oct 3, 2022 at 20:35
  • 3
    use pip3.8 in command line instead of pip when doing pip install. for example: pip3.8 install packageName and not pip install packageName. or consider uninstalling the previous python version if you are not using it Commented Oct 3, 2022 at 20:46
  • 1
    You can use whereis on linux to find any offenders, I'd start with whereis pip3.7 and whereis python3.7 and for sanity generalize it after those are addressed with whereis pip etc. Commented Oct 3, 2022 at 21:17
  • 1
    pip is normal Python script and you can open it in editor and change first line with shebang (#!) to use python3.8 instead of python3.7 - like #!/usr/bin/python3.8. But sometimes pip can be only link to pip3.7 and you can remove pip and create new pip as link to pip3.8 Commented Oct 3, 2022 at 23:06

2 Answers 2

1

python3.8 -m pip install SomePackage # specifically Python 3.8 should work.

More documentation here: https://docs.python.org/3/installing/index.html#work-with-multiple-versions-of-python-installed-in-parallel

Sign up to request clarification or add additional context in comments.

Comments

0

Just to summarize the comments and suggestions from other answers:

The problem I have was caused by the fact that even I had set Python 3.8 as default and python -v was pointing to Python 3.8 the pip script was installing modules for Python 3.7.

The suggested solution was to use pip3.8 (or whatever version someone might have) to install packages for that equivalent Python version and that works good.

Ideally best option if someone wants to have multiple versions of python is to use pyenv. You can create multiple virtual environments with multiple python versions.

However Do not uninstall the default Python. I have also tried to uninstall the default Python 3.7 to avoid having two versions of python 3 and keeping track of which module is installed where. This was a bad idea. I did not know that many Linux distributions have applications which use the default Python. You might get a black screen and who knows what other problems see this discussion Removed Python 3 on 18.04, how can I fix my system?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.