python-import

Simple case of __init__.py and import giving mysterious module not found

一曲冷凌霜 提交于 2020-08-10 19:31:11
问题 I've tried this from so many different angles but can't sort it out. Must be such a simple case. In Python 3.7.6: Directory structure: ./modtest/ ./modtest/__init__.py ./modtest/test1.py ./modtest/test2.py test1.py: import modtest def x(i): print(i) y(i) test2.py: def y(i): print(i) __init__.py is an empty file. When I attempt to run the code: $ /Users/pitosalas/miniconda3/bin/python /Users/pitosalas/mydev/rsb_py/modtest/test1.py Traceback (most recent call last): File "/Users/pitosalas/mydev

ModuleNotFoundError: No module named 'model'

点点圈 提交于 2020-08-10 19:30:52
问题 I have a package with the following structure: model\ __init__.py (from model.main_trainer import *, etc.) main_trainer.py snn.py splitter.py The main_trainer.py script takes at least three arguments as inputs: #main_trainer.py import numpy as np # Linear algebra import pandas as pd # Data wrangling import re # Regular expressions import matplotlib # Avoid plotting graphs matplotlib.use('Agg') # Custom dependencies from model.snn import * from model.splitter import * def main_trainer(dataset

ModuleNotFoundError: No module named 'model'

久未见 提交于 2020-08-10 19:30:25
问题 I have a package with the following structure: model\ __init__.py (from model.main_trainer import *, etc.) main_trainer.py snn.py splitter.py The main_trainer.py script takes at least three arguments as inputs: #main_trainer.py import numpy as np # Linear algebra import pandas as pd # Data wrangling import re # Regular expressions import matplotlib # Avoid plotting graphs matplotlib.use('Agg') # Custom dependencies from model.snn import * from model.splitter import * def main_trainer(dataset

Pycharm imports from Git Submodule

北慕城南 提交于 2020-08-05 05:04:52
问题 I have a python project in Pycharm, wherein there is a nested Git submodule. Here is the folder structure: my-git-repo git-submodule-repo package1 foo.py bar.py package2 baz.py .gitmodules The imports in git-submodule-repo are structured as follows: foo.py: from package1.bar import some_func However, Pycharm doesn't recognize this and wants me to instead have the following: foo.py: from git-submodule-repo.package1.bar import some_func This is problematic because I don't want to have to change