I am on macOS. I recently upgraded my python version via homebrew, but running python3
was still getting the old version of Python 3.8. Therefore, I changed my PATH
variable with export PATH="/usr/local/bin:$PATH"
to use the new Python version 3.12.5.
However, now when I try to import any libraries in Python that I’ve pip installed in the past, Python gives me a ModuleNotFoundError: No module named 'chromadb'
error. I show chromadb, but any package I try to import gives ModuleNotFoundError
.
But of course, I have pip installed and used these packages in the past, and using my old version of Python works fine. When I try to pip install these packages again, I get lots of messages saying requirement already satisfied Requirement already satisfied: chromadb in ./Library/Python/3.8/lib/python/site-packages (0.5.5)
.
I have tried changing my $PYTHONPATH
to include ./Library/Python/3.8/lib/python/site-packages:/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages:
because I saw that these are the locations of some of my site-packages, but that’s getting errors when importing several libraries. For example, when I import redis
or import numpy
I’m getting more ModuleNotFoundError
.
I need to use this updated Python version, but how can I fix the ModuleNotFoundError
‘s? Thanks in advance.
2
Answers
You should not have multiple versions of python installed, not safe and a headache to manage. In your case, you cannot use previously installed packages because you installed them for pyuthon3.8 and your new python don’t have them.
You could try to create a virtual environment and then install your packages there. It’s best to have a separate virtual environment for each project. If you don’t have projects perse, create a virtual environment for your specific python version.
I would recommend using Anaconda or Miniconda for that.
As already stated by others you should use some solution to manage your different development environments if you really want to have several python versions at the same time.
I would recommend you to have a look into poetry for example (https://python-poetry.org/docs/). There you could state your python version and depencies in a so called pyproject.toml.
In your case the
tool.poetry.dependencies
section could look like:or something. The basic usage can be found here.
This makes it much easier to manage different projects with different python and package versions.