relative-import

Attempted relative import beyond toplevel package

半城伤御伤魂 提交于 2020-01-20 02:16:50
问题 Here is my folder structure: Mopy/ # no init.py ! bash/ __init__.py bash.py # <--- Edit: yep there is such a module too bass.py bosh/ __init__.py # contains from .. import bass bsa_files.py ... test_bash\ __init__.py # code below test_bosh\ __init__.py test_bsa_files.py In test_bash\__init__.py I have: import sys from os.path import dirname, abspath, join, sep mopy = dirname(dirname(abspath(__file__))) assert mopy.split(sep)[-1].lower() == 'mopy' sys.path.append(mopy) print 'Mopy folder

Attempted relative import beyond toplevel package

爷,独闯天下 提交于 2020-01-20 02:16:48
问题 Here is my folder structure: Mopy/ # no init.py ! bash/ __init__.py bash.py # <--- Edit: yep there is such a module too bass.py bosh/ __init__.py # contains from .. import bass bsa_files.py ... test_bash\ __init__.py # code below test_bosh\ __init__.py test_bsa_files.py In test_bash\__init__.py I have: import sys from os.path import dirname, abspath, join, sep mopy = dirname(dirname(abspath(__file__))) assert mopy.split(sep)[-1].lower() == 'mopy' sys.path.append(mopy) print 'Mopy folder

Attempted relative import beyond toplevel package

安稳与你 提交于 2020-01-20 02:16:00
问题 Here is my folder structure: Mopy/ # no init.py ! bash/ __init__.py bash.py # <--- Edit: yep there is such a module too bass.py bosh/ __init__.py # contains from .. import bass bsa_files.py ... test_bash\ __init__.py # code below test_bosh\ __init__.py test_bsa_files.py In test_bash\__init__.py I have: import sys from os.path import dirname, abspath, join, sep mopy = dirname(dirname(abspath(__file__))) assert mopy.split(sep)[-1].lower() == 'mopy' sys.path.append(mopy) print 'Mopy folder

How to use relative import without doing python -m?

ぃ、小莉子 提交于 2020-01-06 14:37:18
问题 I have a folder like this /test_mod __init__.py A.py test1.py /sub_mod __init__.py B.py test2.py And I want to use relatives imports in test1 and test2 like this #test1.py from . import A from .sub_mod import B ... #test2.py from .. import A from . import B ... While I develop test1 or test2 I want that those imports to work while I am in the IDLE, that is if I press F5 while working in test2 that every work fine, because I don't want to do python -m test_mod.sub_mod.test2 for instance. I

How to use relative import without doing python -m?

半腔热情 提交于 2020-01-06 14:36:13
问题 I have a folder like this /test_mod __init__.py A.py test1.py /sub_mod __init__.py B.py test2.py And I want to use relatives imports in test1 and test2 like this #test1.py from . import A from .sub_mod import B ... #test2.py from .. import A from . import B ... While I develop test1 or test2 I want that those imports to work while I am in the IDLE, that is if I press F5 while working in test2 that every work fine, because I don't want to do python -m test_mod.sub_mod.test2 for instance. I

Builtin python's __import__ vs imp.load_module: ValueError: Attempted relative import beyond toplevel package

喜你入骨 提交于 2020-01-05 07:02:24
问题 I have a piece of code that dynamically imports a bunch of subpackages - package structure: main_package/ code_below_is_here.py game/ __init__.py game1/ __init__.py constants.py records.py ... game2/ __init__.py constants.py records.py ... using the __import__ function (disclaimer: I did not write that code I 'm just the current maintainer): import pkgutil import game as game_init# <----- I import the game/ package # Detect the known games for importer,modname,ispkg in pkgutil.iter_modules

Python: weird import behaviour

余生颓废 提交于 2019-12-24 09:19:05
问题 I have a package with the following structure projectX ├── data ├── results └── projectX ├── stats │ ├── __init__.py │ ├── stats_worker.py │ └── stats_wroker2.py ├── __init__.py ├── main_worker.py └── interface.py Notice that the project folder and the source folder share the same name (projectX). The problem is a bit complex and needs some premises to be done Premises: I always launch the interface and always have launched the interface. No other script is called My problem first arose when

Python relative-import script two levels up

ぐ巨炮叔叔 提交于 2019-12-20 10:23:31
问题 I've been struggling with imports in my package for the last hour. I've got a directory structure like so: main_package | | __init__.py | folder_1 | | __init__.py | | folder_2 | | | __init__.py | | | script_a.py | | | script_b.py | | folder_3 | | __init__.py | | script_c.py I want to access code in script_b.py as well as code from script_c.py from script_a.py . How can I do this? If I put a simple import script_b inside script_a.py , when I run from main_package.folder_1.folder_2 import

Python relative-import script two levels up

流过昼夜 提交于 2019-12-20 10:20:03
问题 I've been struggling with imports in my package for the last hour. I've got a directory structure like so: main_package | | __init__.py | folder_1 | | __init__.py | | folder_2 | | | __init__.py | | | script_a.py | | | script_b.py | | folder_3 | | __init__.py | | script_c.py I want to access code in script_b.py as well as code from script_c.py from script_a.py . How can I do this? If I put a simple import script_b inside script_a.py , when I run from main_package.folder_1.folder_2 import