“ImportError: No module named” when trying to run Python script

I’m trying to run a script that launches, amongst other things, a python script. I get a ImportError: No module named …, however, if I launch ipython and import the same module in the same way through the interpreter, the module is accepted. What’s going on, and how can I fix it? I’ve tried to … Read more

Python error “ImportError: No module named”

Python is installed in a local directory. My directory tree looks like this: (local directory)/site-packages/toolkit/interface.py My code is in here: (local directory)/site-packages/toolkit/examples/mountain.py To run the example, I write python mountain.py, and in the code I have: from toolkit.interface import interface And I get the error: Traceback (most recent call last): File “mountain.py”, line 28, in … 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: import time from entity import Ent from vector import Vect #the rest just creates an entity and prints … Read more

How to fix “Attempted relative import in non-package” even with __init__.py

I’m trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py In core_test.py I have the following import statement from ..components.core import GameLoopEvents However, when I run, I get the following error: tests$ python core_test.py Traceback (most recent call last): File “core_test.py”, line 3, in <module> from … Read more

Importing files from different folder

I have the following folder structure. application ├── app │   └── folder │   └── file.py └── app2 └── some_folder └── some_file.py I want to import some functions from file.py in some_file.py. I’ve tried from application.app.folder.file import func_name and some other various attempts but so far I couldn’t manage to import properly. How can I do … Read more