Python 'cannot import name'

1.6k Views Asked by At

So i have structure like this

enter image description here

And i want to import userlist.py from server.py. Server py:

import socket

from server import userlist #<-- error here

class Server():
    def __init__(self,port):

Other files in server don't have any refferences to userlist. It says cannot import name userlist

If i change import to

from server.userlist import Userlist

it says: 'server' is not a package

1

There are 1 best solutions below

0
On BEST ANSWER

Try just

import userlist

When you are importing a file (module) in the same directory, all you need to do is import the name of that file without the .py part.