tagged [python-import]

Why is Python running my module when I import it, and how do I stop it?

Why is Python running my module when I import it, and how do I stop it? I have a Python program I'm building that can be run in either of 2 ways: the first is to call `python main.py` which prompts th...

21 Oct at 02:19

'ModuleNotFoundError' when trying to import module from imported package

'ModuleNotFoundError' when trying to import module from imported package This is my directory structure: `man1.py` contains the fo

7 May at 16:25

Python error "ImportError: No module named"

Python error "ImportError: No module named" Python is installed in a local directory. My directory tree looks like this: My code is in here: To run the example, I write `python mountain.py`, and in t...

15 Aug at 19:50

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

How to fix "Attempted relative import in non-package" even with __init__.py I'm trying to follow [PEP 328](http://www.python.org/dev/peps/pep-0328/), with the following directory structure: In `core_t...

Importing a long list of constants to a Python file

Importing a long list of constants to a Python file In Python, is there an analogue of the `C` preprocessor statement such as?: `#define MY_CONSTANT 50` Also, I have a large list of constants I'd like...

25 Feb at 15:26

Error importing Seaborn module in Python: "ImportError: cannot import name utils"

Error importing Seaborn module in Python: "ImportError: cannot import name utils" I am trying to import seaborn into python (using 2.7) using the following code: and getting the following error messag...

21 Dec at 22:6

What can I do about "ImportError: Cannot import name X" or "AttributeError: ... (most likely due to a circular import)"?

What can I do about "ImportError: Cannot import name X" or "AttributeError: ... (most likely due to a circular import)"? I have some code spread across multiple files that try to `import` from each ot...

PyCharm import external library

PyCharm import external library I am using PyCharm as an editor for python code in Houdini. Whenever I try to import the main Houdini library (hou) I get an error flagged in PyCharm. If I include the ...

13 Jun at 05:6

Why do circular imports seemingly work further up in the call stack but then raise an ImportError further down?

Why do circular imports seemingly work further up in the call stack but then raise an ImportError further down? I'm getting this error ``` Traceback (most recent call last): File "/Users/alex/dev/run...

11 Aug at 04:8

pytest cannot import module while python can

pytest cannot import module while python can I am working on a package in Python. I use virtualenv. I set the path to the root of the module in a .pth path in my virtualenv, so that I can import modul...

27 Feb at 12:13

ModuleNotFoundError: What does it mean __main__ is not a package?

ModuleNotFoundError: What does it mean __main__ is not a package? I am trying to run a module from the console. The structure of my directory is this: [](https://i.stack.imgur.com/naRKa.png) I am tryi...

Unresolved Import Issues with PyDev and Eclipse

Unresolved Import Issues with PyDev and Eclipse I am very new to PyDev and Python, though I have used Eclipse for Java plenty. I am trying to work through some of the Dive Into Python examples and thi...

23 Feb at 10:45

Relative imports for the billionth time

Relative imports for the billionth time I've been here: - [http://www.python.org/dev/peps/pep-0328/](http://www.python.org/dev/peps/pep-0328/)- [http://docs.python.org/2/tutorial/modules.html#packages...

Visibility of global variables in imported modules

Visibility of global variables in imported modules I've run into a bit of a wall importing modules in a Python script. I'll do my best to describe the error, why I run into it, and why I'm tying this ...

Python: importing a sub‑package or sub‑module

Python: importing a sub‑package or sub‑module Having already use flat packages, I was not expecting the issue I encountered with nested packages. Here is… # Directory layout # Content of init.py Both ...

29 Jul at 19:6

import error: 'No module named' *does* exist

import error: 'No module named' *does* exist I am getting this stack trace when I start pyramid pserve: ``` % python $(which pserve) ../etc/development.ini Traceback (most recent call last): File "/h...

23 Oct at 23:8