0

I'm writing a small script in Python, as a part of my networking class homework.

I have to run this script in cmd.exe, but it keeps giving me error ModuleNotFoundError: No module named 'paramiko'. It only works in IDLE, and only in 3.10 version.

File "C:\Users\drafthard\Documents\routerconfigscript4.py", line 1, in <module>
    import paramiko
ModuleNotFoundError: No module named 'paramiko'

Error screenshot

I've tried reinstalling paramiko, reinstalling pip, clearing pip cache and installing paramiko again, showing path to paramiko files but nothing works.

Any idea how to solve this problem?

import paramiko
import time
user = 'user1'
pass1 = '12345'
port = 22

cisco = ['172.16.0.1', '172.16.0.2']

for host in cisco:
         print('------Start---'+host+'------')
         client = paramiko.SSHClient()
         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
         client.connect(hostname=host, username=user, password=pass1, port=port)
         chan = client.invoke_shell()
         time.sleep(2)
         chan.send('terminal length 0\n')
         time.sleep(1)
         chan.send('show run\n')
         time.sleep(1)
         result = chan.recv(5000).decode('utf-8')
         filename= str(host)+'.txt'
         file=open(filename, 'w')
         file.write(result)
         file.close()
         print(result)
         time.sleep(2)
         client.close()
         print('------End-----'+host+'------')
Compo
  • 36,585
  • 5
  • 27
  • 39
drafthard
  • 11
  • 3
  • 1
    Please don't add screenshots of code, errors, or any other textual content. Please edit your question and add the error to your question directly. – Holger Just Feb 01 '23 at 16:56
  • 1
    Like Holger said, please add the error directly. Also, make sure that you are in the right environment and using the right python version. you may for example have installed paramiko in your python 3.9, but you are running your script with python 3.10. – John Ingram Feb 01 '23 at 16:59
  • I'm trying to run it in command prompt. – drafthard Feb 01 '23 at 17:07
  • Check [\[SO\]: PyCharm doesn't recognize installed module (@CristiFati's answer)](https://stackoverflow.com/a/73363599/4788546). – CristiFati Feb 01 '23 at 17:19

1 Answers1

1

Issue was solved by converting .py file to .exe with auto-py-to-exe and specifiying paramiko module in advanced settings.

drafthard
  • 11
  • 3