ModuleNotFoundError when run from command line

Viewed 3142

I used import nmap module from python-nmap, and it works fine in Pycharm.

But when I try to run the same program on command prompt, it gives error:

ModuleNotFoundError: No module named 'nmap'

pip is installed in the directory path pycharmprojects\botnet\venv\lib\site-packages (0.6.1). This is the same path where my program is located.

Has anyone seen this error?

It doesn't work in cmd instead of Pycharm. in cmd not working in pycharm everything works fine//

Pycharm terminal says it's installed in the path where it should be installed. //pycharm terminal says its installed in the path where it should be installed i guess..

1 Answers

In the first image, you don't have your virtual environment activated. Because you only have python-nmap installed in your virtual environment python, your system-wide python installation can't find it.

In the second image, you do have the virtual environment activated, which is why it says python-nmap is installed.

To activate your virtual environment on Windows, you need to execute \path\to\your\venv\bin\activate.exe. Then run your command and it should work.

Alternatively, you could just run pip install python-nmap to install it on your system level python installation.

Related