2

Can you help with a definitive answer for MAC and PC.

I have come across similar questions to this quite a lot on stackoverflow where a user will be using an editor such as IDLE or ATOM and they will get the module not found error, then they will go to terminal or command line prompt and try to pip install the module, and it will either install the module or say requirement already satisfied.

On returning to the editor and running the script it will still give the module not found error.

I have seen the same question, but often asked about for specific modules.

This error started happening a lot for me when I was required to install anaconda for a course and was required to use other editors, but had previously been using a download of Python and working with IDLE.

I often go between a MAC and a PC, where I have got the same issue, where I have an instance of anaconda installed and another instance of python installed.

It is very confusing how to untangle the different paths where some have modules and other don't.

Could someone give some advice on how to rectify this? I wonder if there is a solution where I could do a pip install that would globally update all versions of python with a module?

Christopher
  • 427
  • 1
  • 8
  • 18

1 Answers1

8

This could happen if you have multiple versions of Python installed on your computer. For example you have a package installed on Python 3.5 but you run your script on Python 3.8. On cmd or Powershell you could try something like py -3.8 -m pip list or py -3.5 -m pip list to check which libraries you have installed on each version of Python. Then if the library is missing from the version that you used on your script you can install it specifically for this version using something like py -3.5 -m pip install library_name.

Stamatis Tiniakos
  • 698
  • 1
  • 11
  • 33
  • Awesome answer Stamatis Tiniakos, I wish I could upvote this more than once. I wonder if it is possible to write a Python script that can list all Pythons present and simultaneously install the missing library. Is there an easy way to find out which Pythons I have installed? I am slightly more familiar with searching PC than MAC. – Christopher Mar 21 '21 at 01:35
  • 1
    On cmd you could type 'py' or 'python' and then press enter. This will show you which python library is on path and therefore is used when you run your script. On windows python files are usually installed on the following location : "C:\Users\your_user_name\AppData\Roaming\Python". You can check there to see which versions you have installed. – Stamatis Tiniakos Mar 21 '21 at 01:45
  • 1
    On windows there is an apps & features section on the control panel. You can also see there which versions of python you have installed. – Stamatis Tiniakos Mar 21 '21 at 01:50
  • 1
    Stamatis Tiniakos, your answers have really given me some great insight on how to approach the issue. I have just found a very useful link about how to do similar for the MAC https://stackoverflow.com/questions/33175827/what-version-of-python-is-on-my-mac You could have multiple Python versions on your macOS. You may check that by command, type or which command, like: which -a python python2 python2.7 python3 python3.6 Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to: compgen -c python – Christopher Mar 21 '21 at 01:57
  • when I type `py --version`, it is showing 3.10.x. But still `pip list` and `py -3.10 -m pip list` are showing different list. Why so? (PS: Yes, I have different python versions in path, but still couldn't explain this behaviour) – Sourav Kannantha B Nov 04 '21 at 06:05