0

I am new to Python so this may be a stupid question, sorry in advance if it is so!

The paths Python searches for modules using Spyder 4.1.4.:

[.., 'D:\Users\Martin\Anaconda3\lib\site-packages', ..]

The paths Python searches for when used via command line in windows:

[.., 'D:\Users\Martin\Anaconda3\lib\site-packages', ..]

Thus, both include path to

'D:\Users\Martin\Anaconda3\lib\site-packages'

where I store my cv2 module installed. Yet, Spyder can import cv2 and to my surprise cmd cannot import cv2 with an error No module named 'cv2'. What am I missing please? Can anyone verify if it works for him in command line please? (I changed/edited the question again to cut unneccessary long talk, though the essence stayed the same, in hope someone could answer).

Martin
  • 119
  • 8

1 Answers1

0

I solved it. If you have a similar problem, you can check if your case is similar to mine and follow the steps.

I use Spyder and everything works fine. However my goal is to use Python via cmd. This could not be done because Python via cmd could not find my modules.

What I did: After typing python in cmd, Python worked and output its version by default. However, I noticed the version was different than version running in Spyder - I had two Python installations (one of which I didn't know about). I found the installation cmd uses by import sys and print(sys.executable). I uninstalled that Python installation.

Now, typing python in cmd does not do anything, it is an unknown command. Then I followed this guide to add my Python installation to Path (using Windows) by:

My Computer > Properties > Advanced System Settings > Environment Variables >

in System variables, I found "Path", clicked Edit, New, then input my Python installation path D:\Users\Martin\Anaconda3 as well as D:\Users\Martin\Anaconda3\Scripts and D:\Users\Martin\Anaconda3\Library\bin. This solved it for me.

Martin
  • 119
  • 8