relative-import

Python packages: relative imports

为君一笑 提交于 2019-12-19 08:28:02
问题 I'm working on a Python application consisting of a core and multiple independent modules using the core. I'm having difficulty setting up relative imports of packages. app |- __init__.py |- core |- __init__.py |- corefile.py |- module1 |- __init__.py |- main.py The __init__.py files are empty. I'm running Python 2.7.1. main.py from .core import * Running python main.py results in ValueError: Attempted relative import in non-package . Similar questions: Ultimate answer to relative python

Pycharm auto relative imports

两盒软妹~` 提交于 2019-12-19 05:13:09
问题 Whenever you use autoimport provided by PyCharm it generates an absolute path import. i.e. from my_package.my_subpackage import my_thing instead of from .my_subpackage import my_thing Is there a setting to use relative imports instead of absolute ones when importing a python package? 回答1: It appears currently there is no way to change the import style for auto-import feature to use relative imports. The only style changes you can make to import statements are how the absolute imports are

Python packages: relative imports

牧云@^-^@ 提交于 2019-12-01 07:34:50
I'm working on a Python application consisting of a core and multiple independent modules using the core. I'm having difficulty setting up relative imports of packages. app |- __init__.py |- core |- __init__.py |- corefile.py |- module1 |- __init__.py |- main.py The __init__.py files are empty. I'm running Python 2.7.1. main.py from .core import * Running python main.py results in ValueError: Attempted relative import in non-package . Similar questions: Ultimate answer to relative python imports , How to do relative imports in Python? , Relative imports in Python Thanks for the help. In short,

Python project structure and relative imports

夙愿已清 提交于 2019-12-01 04:33:19
问题 I'm new to Python and I searched google a lot and read some articles about relative imports etc. Despite the fact that I am unable to get it working. Please, consider my following project structure: /Project /docs /log /prev /src a.py /tests /tests1 b.py /tests2 .gitignore README.txt program.py And what I'm trying to achieve is to import a class from file a.py inside of the script b.py . Generally speaking, script b.py should have line with import of a.py . I've read some articles about using

Python importing a module from a parallel directory

ε祈祈猫儿з 提交于 2019-11-30 07:00:48
How would I organize my python imports so that I can have a directory like this. project | \ | __init__.py | src | \ | __init__.py | classes.py | test \ __init__.py tests.py And then inside /project/test/tests.py be able to import classes.py I've got code looking like this in tests.py from .. src.classes import( scheduler db ) And am getting errors of SystemError: Parent module '' not loaded, cannot perform relative import Anyone know what to do? Python adds the folder containing the script you launch to the PYTHONPATH, so if you run python test/tests.py Only the folder test is added to the

import local function from a module housed in another directory with relative imports in jupyter notebook using python3

笑着哭i 提交于 2019-11-28 15:22:34
I have a directory structure similar to the following meta_project project1 __init__.py lib module.py __init__.py notebook_folder notebook.jpynb When working in notebook.jpynb if I try to use a relative import to access a function function() in module.py with: from ..project1.lib.module import function I get the following error SystemError Traceback (most recent call last) <ipython-input-7-6393744d93ab> in <module>() ----> 1 from ..project1.lib.module import function SystemError: Parent module '' not loaded, cannot perform relative import Is there any way to get this to work using relative

Relative import error with py2exe

自作多情 提交于 2019-11-27 15:30:03
I was trying to generate an executable for a simple Python script. My setup.py code looks like this: from distutils.core import setup import py2exe setup(console=["script.py"]) However, I am getting the error shown in the screenshot. Is there something I could try to fix this? I am using Windows 10. mabe02 It seems that in your mf3.py you are importing beyond the top level . Let's suppose that your project structure is as follows: folder/ main.py mod/ __init__.py components/ __init__.py expander.py language_id.py utilities/ __init__.py functions.py First make sure that main.py refers to the

Python importing a module from a parallel directory

假装没事ソ 提交于 2019-11-27 15:04:54
问题 How would I organize my python imports so that I can have a directory like this. project | \ | __init__.py | src | \ | __init__.py | classes.py | test \ __init__.py tests.py And then inside /project/test/tests.py be able to import classes.py I've got code looking like this in tests.py from .. src.classes import( scheduler db ) And am getting errors of SystemError: Parent module '' not loaded, cannot perform relative import Anyone know what to do? 回答1: Python adds the folder containing the

import local function from a module housed in another directory with relative imports in jupyter notebook using python3

我的梦境 提交于 2019-11-26 23:55:16
问题 I have a directory structure similar to the following meta_project project1 __init__.py lib module.py __init__.py notebook_folder notebook.jpynb When working in notebook.jpynb if I try to use a relative import to access a function function() in module.py with: from ..project1.lib.module import function I get the following error SystemError Traceback (most recent call last) <ipython-input-7-6393744d93ab> in <module>() ----> 1 from ..project1.lib.module import function SystemError: Parent

Relative imports - ModuleNotFoundError: No module named x

五迷三道 提交于 2019-11-26 21:25:52
This is the first time I've really sat down and tried python 3, and seem to be failing miserably. I have the following two files: test.py config.py config.py has a few functions defined in it as well as a few variables. I've stripped it down to the following: However, I'm getting the following error: ModuleNotFoundError: No module named 'config' I'm aware that the py3 convention is to use absolute imports: from . import config However, this leads to the following error: ImportError: cannot import name 'config' So I'm at a loss as to what to do here... Any help is greatly appreciated. :) TL;DR: