Namespace error on jupyter IDE

I got the following error on the jupyter IDE that am using to learn python:

“NameError: name ‘int’ is not defined” because in the previous error, it complained that " account is not a package"

I did some research and did the following to see if the problem could be fixed:

  1. I created a package that I called package
  2. Created an empty init python file:" init.py.
  3. uploaded the init file and my python code and ran it and am still getting the same error
    I then put this line “import init.py” on top of my python file, executed the code and the problem is still there.

Please help if you have an idea that I could try so that I do not waste this friday on this error

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Is this after running a certain piece of code or is when you attempt to start the notebook?

Is it was the notebook then perhaps there was an issue with the original install. Possibly some dependencies were missed or something along those lines which would explain why certain things aren’t defined when they should be. Personally I’d consider clearing up that install, removing everything and reinstalling it. That might be easier than trying to fix it yourself, it’s your call though. Depending on your package manager the downloads may still be saved somewhere so a reinstall should be fairly quick.

no, this was while trying to run the module(piece of code i wrote that i wanted to use in a different code. i imported like so:

import myinit file( # this init file is a one line "init.py
import mymodule .py( #has about 40 lines of accounting processing. works ok on its own

Are those whitespaces what you typed out or are they included in the original import? I can see that being an issue, You could also do without the .py extension.

Try each of them separately so you know where your problem is coming from.

__int__.py

that is the init line that I read to include so python could treat the file you import as a package

so part of creating a module to be reused is by including int.py in an empty file.py the__int__.py text
so to run the code in jupyter, i imported the initfile.py and mycode.py

I don’t know what your code contains but those import statements look problematic to me. I suggest you check carefully how to import your own modules and packages.

what do you suggest as a correction?

Get rid of whitespaces (whilst there are ways to get around this problem best practice would be to avoid them entirely in your package name) and .py extensions. It should not look any different to how you import anything else- https://docs.python.org/3/reference/simple_stmts.html#the-import-statement

do you mean the spaces on the left and right side of the 'unit’s or which other white spaces do you mean? the left and right sides of the init are 2 underscores on left and right. thank you for helping.

I think i have resolved this. whitespaces were not the problem. I went about importing the module a different way . To help anybody who might have similar problem, including this one line:
from codetobeimported import * at the very top of the code that is importing the other code