How to import the class within the same directory or sub directory?

Python 2 Make an empty file called __init__.py in the same directory as the files. That will signify to Python that it’s “ok to import from this directory”. Then just do… The same holds true if the files are in a subdirectory – put an __init__.py in the subdirectory as well, and then use regular import statements, with dot … Read more

How do I unload (reload) a Python module?

You can reload a module when it has already been imported by using importlib.reload(): In Python 2, reload was a builtin. In Python 3, it was moved to the imp module. In 3.4, imp was deprecated in favor of importlib. When targeting 3 or later, either reference the appropriate module when calling reload or import it. I think that this is what you want. Web servers like Django’s development … Read more

How to import the class within the same directory or sub directory?

Python 2 Make an empty file called __init__.py in the same directory as the files. That will signify to Python that it’s “ok to import from this directory”. Then just do… The same holds true if the files are in a subdirectory – put an __init__.py in the subdirectory as well, and then use regular import statements, with dot … Read more

ImportError: Cannot import name X

I have four different files named: main.py, vector.py, entity.py and physics.py. I will not post all the code, just the imports, because I think that’s where the error is (If you want, I can post more). main.py: entity.py: vector.py: physics.py: I then run from main.py and I get the following error: I’m guessing that the error is due to importing entity twice, … Read more

ImportError: No module named requests

Requests is not a built in module (does not come with the default python installation), so you will have to install it: OSX/Linux Use $ pip install requests (or pip3 install requests for python3) if you have pip installed. If pip is installed but not in your path you can use python -m pip install requests (or python3 -m pip install requests for python3) Alternatively … Read more