Can't import whois in .py file, but can in shell

186 Views Asked by At

I have recently installed whois.

When I try to import the whois module in a .py file I get a ModuleNotFoundError. However, when I give the import command in a Python shell the problem does not occur, and the module imports as expected. Each time I am using the same command:

import whois

When using the shell I can get more information about the location the module was imported from:

import whois
whois
<module 'whois' from 'C:\\Users\\Name\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\whois\\__init__.py'>

Why would a python shell in the same directory as the .py file have different behavior than said file? hat can I do to rectify it?

1

There are 1 best solutions below

0
Green Joffer On

Try

from .folder import whois

if doesn't work - try to create in that folder empty file __init__.py, restart ide or what and try again