Linked Questions
108 questions linked to/from Import a module from a relative path
44 votes
3 answers
98k views
How to access a module from outside your file folder in Python? [duplicate]
How can I access modules from another folder? Here's the file structure: /<appname> /config __init__.py config.py /test test.py # I'm here I wanted to access ...
6 votes
3 answers
14k views
Importing modules from nested folder [duplicate]
I have a folder structure like this main_folder | |--done | | | |--test1 | |--__init__.py | |---check.py __init__.py: class Tries(object): def __init__(self): print "Test" check.py: ...
4 votes
3 answers
1k views
python relative import [duplicate]
I'm trying to make a relative import in python. but I can't understand the syntax and everytime I search for it here in SO, I can't get an answer: Here is my folder structure: Root libraries ...
0 votes
2 answers
4k views
Import module from subfolder in Python [duplicate]
I want to import modules from subfolers in Python. It works from main.py to the subfolder, but not from subfolder to subfolder. Every folder has a __init__.py This is how the folder structure looks ...
0 votes
1 answer
443 views
import subfolder in python [duplicate]
I have folder structure as follows: /foo/trunk/mss/cloud and /foo/trunk/mss/model my python file is located at subfolder model with name test.py I want to import all modules located in subfolder ...
-1 votes
1 answer
188 views
How to import package properly [duplicate]
I have some projects I try to split up for easier management. Therefor I moved some parts that are used by different applications into modules rather than copying files around. Right now I have the ...
-2 votes
2 answers
65 views
Python use basic code across folders [duplicate]
I have python code with the directory structure - main.py basics.py component1 file1.py file2.py component2 file1.py file2.py I want the code in the directories component1 and component2 ...
1868 votes
38 answers
1.6m views
How can I import a module dynamically given the full path?
How do I load a Python module given its full path? Note that the file can be anywhere in the filesystem where the user has access rights. See also: How to import a module given its name as string?
857 votes
24 answers
683k views
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 ...
969 votes
20 answers
1.7m views
How to import the class within the same directory or sub directory?
I have a directory that stores all the .py files. bin/ main.py user.py # where class User resides dir.py # where class Dir resides I want to use classes from user.py and dir.py in main.py. ...
630 votes
17 answers
441k views
How can I do relative imports in Python?
Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding mod1, and I need to import something from mod2. How ...
446 votes
21 answers
1.0m views
Relative paths in Python [duplicate]
I'm building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don't, however, have the absolute path to the directory where the ...
205 votes
12 answers
90k views
Why is "import *" bad? [duplicate]
It is recommended to not to use import * in Python. Can anyone please share the reason for that, so that I can avoid it doing next time?
103 votes
5 answers
60k views
Import arbitrary python source file. (Python 3.3+)
How can I import an arbitrary python source file (whose filename could contain any characters, and does not always ends with .py) in Python 3.3+? I used imp.load_module as follows: >>> ...
49 votes
7 answers
86k views
I can't seem to get --py-files on Spark to work
I'm having a problem with using Python on Spark. My application has some dependencies, such as numpy, pandas, astropy, etc. I cannot use virtualenv to create an environment with all dependencies, ...