Import module from subfolderPython imports from subfoldersImporting my own modules in Google App EngineHow to import a directory with modules to Python path that is a symlink to original source from a subfolder?Import forked module in Python instead of installed moduleCreate a python package & install it as source distribution and not a .egg?Import module errorGetting error when importing from sibling packageImporting a class from one directory to another directoryPython Relative Imports “Above Top Level”Avoid to import the path when using subfolders in pythonCalling a function of a module by using its name (a string)How to import a module given the full path?Import a module from a relative pathImporting modules from parent folderHow can I get a list of locally installed Python modules?Why is Python running my module when I import it, and how do I stop it?How to import a module in Python with importlib.import_moduleHow to import an SQL file using the command line in MySQL?import subfolder in pythonHow to import and create my class from my module?

Converting 3x7 to a 1x7. Is it possible with only existing parts?

What things do I only get a limited opportunity to take photos of?

A Tale of Snake and Coffee

What made the Ancient One do this in Endgame?

The last tree in the Universe

New Site Design!

How to remove multiple elements from Set/Map AND knowing which ones were removed?

Does the use of English words weaken diceware passphrases

Reflecting Telescope Blind Spot?

Why does MAGMA claim that the automorphism group of an elliptic curve is order 24 when it is order 12?

What is the color associated with lukewarm?

Difference between "drift" and "wander"

How to know whether to write accidentals as sharps or flats?

Should I worry about having my credit pulled multiple times while car shopping?

How to avoid offending original culture when making conculture inspired from original

Struggling to present results from long papers in short time slots

At zero velocity, is this object neither speeding up nor slowing down?

Cremated People Pottery

Digital signature that is only verifiable by one specific person

Is it a bad idea to have an pen name within only an initial for a surname?

Why is gun control associated with the socially liberal Democratic party?

Does WiFi affect the quality of images downloaded from the internet?

Does anyone recognize these rockets, and their location?

How to make a villain when your PCs are villains?



Import module from subfolder


Python imports from subfoldersImporting my own modules in Google App EngineHow to import a directory with modules to Python path that is a symlink to original source from a subfolder?Import forked module in Python instead of installed moduleCreate a python package & install it as source distribution and not a .egg?Import module errorGetting error when importing from sibling packageImporting a class from one directory to another directoryPython Relative Imports “Above Top Level”Avoid to import the path when using subfolders in pythonCalling a function of a module by using its name (a string)How to import a module given the full path?Import a module from a relative pathImporting modules from parent folderHow can I get a list of locally installed Python modules?Why is Python running my module when I import it, and how do I stop it?How to import a module in Python with importlib.import_moduleHow to import an SQL file using the command line in MySQL?import subfolder in pythonHow to import and create my class from my module?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








81















I want to import subfolders as modules. Therefore every subfolder contains a __init__.py. My folder structure is like this:



src
main.py
dirFoo
__init__.py
foofactory.py
dirFoo1
__init__.py
foo1.py
dirFoo2
__init__.py
foo2.py


In my main script I import



from dirFoo.foofactory import FooFactory


In this factory file I include the sub modules:



from dirFoo1.foo1 import Foo1
from dirFoo2.foo2 import Foo2


If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:



Traceback (most recent call last):
File "/Users/tmp/src/main.py", line 1, in <module>
from dirFoo.foofactory import FooFactory
File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
from dirFoo1.foo1 import Foo1
ImportError: No module named dirFoo1.foo1









share|improve this question




























    81















    I want to import subfolders as modules. Therefore every subfolder contains a __init__.py. My folder structure is like this:



    src
    main.py
    dirFoo
    __init__.py
    foofactory.py
    dirFoo1
    __init__.py
    foo1.py
    dirFoo2
    __init__.py
    foo2.py


    In my main script I import



    from dirFoo.foofactory import FooFactory


    In this factory file I include the sub modules:



    from dirFoo1.foo1 import Foo1
    from dirFoo2.foo2 import Foo2


    If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:



    Traceback (most recent call last):
    File "/Users/tmp/src/main.py", line 1, in <module>
    from dirFoo.foofactory import FooFactory
    File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
    from dirFoo1.foo1 import Foo1
    ImportError: No module named dirFoo1.foo1









    share|improve this question
























      81












      81








      81


      22






      I want to import subfolders as modules. Therefore every subfolder contains a __init__.py. My folder structure is like this:



      src
      main.py
      dirFoo
      __init__.py
      foofactory.py
      dirFoo1
      __init__.py
      foo1.py
      dirFoo2
      __init__.py
      foo2.py


      In my main script I import



      from dirFoo.foofactory import FooFactory


      In this factory file I include the sub modules:



      from dirFoo1.foo1 import Foo1
      from dirFoo2.foo2 import Foo2


      If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:



      Traceback (most recent call last):
      File "/Users/tmp/src/main.py", line 1, in <module>
      from dirFoo.foofactory import FooFactory
      File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
      from dirFoo1.foo1 import Foo1
      ImportError: No module named dirFoo1.foo1









      share|improve this question














      I want to import subfolders as modules. Therefore every subfolder contains a __init__.py. My folder structure is like this:



      src
      main.py
      dirFoo
      __init__.py
      foofactory.py
      dirFoo1
      __init__.py
      foo1.py
      dirFoo2
      __init__.py
      foo2.py


      In my main script I import



      from dirFoo.foofactory import FooFactory


      In this factory file I include the sub modules:



      from dirFoo1.foo1 import Foo1
      from dirFoo2.foo2 import Foo2


      If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:



      Traceback (most recent call last):
      File "/Users/tmp/src/main.py", line 1, in <module>
      from dirFoo.foofactory import FooFactory
      File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
      from dirFoo1.foo1 import Foo1
      ImportError: No module named dirFoo1.foo1






      python import module subdirectory






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 21 '12 at 14:44









      RazerRazer

      3,42293879




      3,42293879






















          5 Answers
          5






          active

          oldest

          votes


















          108














          There's no need to mess with your PYTHONPATH or sys.path here.



          To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:



          from dirFoo.dirFoo1.foo1 import Foo1
          from dirFoo.dirFoo2.foo2 import Foo2


          Or you can use relative imports:



          from .dirfoo1.foo1 import Foo1
          from .dirfoo1.foo1 import Foo2





          share|improve this answer


















          • 41





            One thing to remember! add __init__.py to every subfolder you are importing from.

            – Aziz Alto
            Sep 9 '15 at 1:33






          • 5





            Empty __init__.py may do the job.

            – cerebrou
            Jan 13 '17 at 8:07











          • What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

            – jxramos
            Apr 12 '17 at 23:41











          • @AzizAlto: without your comment this solution is not very useful

            – Alex
            Oct 19 '18 at 14:09


















          17














          Just to notify here. (from a newbee, keviv22)



          Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.



          Invalid Folder namings as follows:



          • Generic-Classes-Folder

          • Generic_Classes_Folder

          valid Folder namings for above:



          • GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)

          What mistake I did:



          consider the file structure.



          Parent
          . __init__.py
          . Setup
          .. __init__.py
          .. Generic-Class-Folder
          ... __init__.py
          ... targetClass.py
          . Check
          .. __init__.py
          .. testFile.py


          What I wanted to do?



          • from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file

          What command I did?



          • from 'testFile.py', wrote command,
            from Core.Generic-Class-Folder.targetClass import functionExecute

          • Got errors like SyntaxError: invalid syntax

          Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py file, inserted environment path and hugely worried what went wrong......



          And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!



          (sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)






          share|improve this answer




















          • 8





            Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

            – cowlinator
            Aug 23 '17 at 22:46


















          5














          Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).



          Also you can manually add your current directory (src in your case) to pythonpath:



          import os
          import sys
          sys.path.insert(0, os.getcwd())





          share|improve this answer
































            1














            Say your project is structured this way:



            +---MyPythonProject
            | +---.gitignore
            | +---run.py
            | | +---subscripts
            | | | +---script_one.py
            | | | +---script_two.py


            Inside run.py, you can import scripts one and two by:



            from subscripts import script_one as One
            from subscripts import script_two as Two


            Now, still inside run.py, you'll be able to call their methods with:



            One.method_from_one(param)
            Two.method_from_two(other_param)





            share|improve this answer






























              -2














              Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import



              from folder.file import Class as Class
              import folder.file as functions





              share|improve this answer























              • That point is not very relevant and just a repetition.

                – crisscross
                Feb 7 at 15:16












              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8953844%2fimport-module-from-subfolder%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              108














              There's no need to mess with your PYTHONPATH or sys.path here.



              To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:



              from dirFoo.dirFoo1.foo1 import Foo1
              from dirFoo.dirFoo2.foo2 import Foo2


              Or you can use relative imports:



              from .dirfoo1.foo1 import Foo1
              from .dirfoo1.foo1 import Foo2





              share|improve this answer


















              • 41





                One thing to remember! add __init__.py to every subfolder you are importing from.

                – Aziz Alto
                Sep 9 '15 at 1:33






              • 5





                Empty __init__.py may do the job.

                – cerebrou
                Jan 13 '17 at 8:07











              • What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

                – jxramos
                Apr 12 '17 at 23:41











              • @AzizAlto: without your comment this solution is not very useful

                – Alex
                Oct 19 '18 at 14:09















              108














              There's no need to mess with your PYTHONPATH or sys.path here.



              To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:



              from dirFoo.dirFoo1.foo1 import Foo1
              from dirFoo.dirFoo2.foo2 import Foo2


              Or you can use relative imports:



              from .dirfoo1.foo1 import Foo1
              from .dirfoo1.foo1 import Foo2





              share|improve this answer


















              • 41





                One thing to remember! add __init__.py to every subfolder you are importing from.

                – Aziz Alto
                Sep 9 '15 at 1:33






              • 5





                Empty __init__.py may do the job.

                – cerebrou
                Jan 13 '17 at 8:07











              • What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

                – jxramos
                Apr 12 '17 at 23:41











              • @AzizAlto: without your comment this solution is not very useful

                – Alex
                Oct 19 '18 at 14:09













              108












              108








              108







              There's no need to mess with your PYTHONPATH or sys.path here.



              To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:



              from dirFoo.dirFoo1.foo1 import Foo1
              from dirFoo.dirFoo2.foo2 import Foo2


              Or you can use relative imports:



              from .dirfoo1.foo1 import Foo1
              from .dirfoo1.foo1 import Foo2





              share|improve this answer













              There's no need to mess with your PYTHONPATH or sys.path here.



              To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:



              from dirFoo.dirFoo1.foo1 import Foo1
              from dirFoo.dirFoo2.foo2 import Foo2


              Or you can use relative imports:



              from .dirfoo1.foo1 import Foo1
              from .dirfoo1.foo1 import Foo2






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 21 '12 at 16:18









              Rob WoutersRob Wouters

              11.9k22832




              11.9k22832







              • 41





                One thing to remember! add __init__.py to every subfolder you are importing from.

                – Aziz Alto
                Sep 9 '15 at 1:33






              • 5





                Empty __init__.py may do the job.

                – cerebrou
                Jan 13 '17 at 8:07











              • What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

                – jxramos
                Apr 12 '17 at 23:41











              • @AzizAlto: without your comment this solution is not very useful

                – Alex
                Oct 19 '18 at 14:09












              • 41





                One thing to remember! add __init__.py to every subfolder you are importing from.

                – Aziz Alto
                Sep 9 '15 at 1:33






              • 5





                Empty __init__.py may do the job.

                – cerebrou
                Jan 13 '17 at 8:07











              • What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

                – jxramos
                Apr 12 '17 at 23:41











              • @AzizAlto: without your comment this solution is not very useful

                – Alex
                Oct 19 '18 at 14:09







              41




              41





              One thing to remember! add __init__.py to every subfolder you are importing from.

              – Aziz Alto
              Sep 9 '15 at 1:33





              One thing to remember! add __init__.py to every subfolder you are importing from.

              – Aziz Alto
              Sep 9 '15 at 1:33




              5




              5





              Empty __init__.py may do the job.

              – cerebrou
              Jan 13 '17 at 8:07





              Empty __init__.py may do the job.

              – cerebrou
              Jan 13 '17 at 8:07













              What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

              – jxramos
              Apr 12 '17 at 23:41





              What would the syntax be if previously Foo1 was in the parent directory and one coded something like from Foo1 import *. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1?

              – jxramos
              Apr 12 '17 at 23:41













              @AzizAlto: without your comment this solution is not very useful

              – Alex
              Oct 19 '18 at 14:09





              @AzizAlto: without your comment this solution is not very useful

              – Alex
              Oct 19 '18 at 14:09













              17














              Just to notify here. (from a newbee, keviv22)



              Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.



              Invalid Folder namings as follows:



              • Generic-Classes-Folder

              • Generic_Classes_Folder

              valid Folder namings for above:



              • GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)

              What mistake I did:



              consider the file structure.



              Parent
              . __init__.py
              . Setup
              .. __init__.py
              .. Generic-Class-Folder
              ... __init__.py
              ... targetClass.py
              . Check
              .. __init__.py
              .. testFile.py


              What I wanted to do?



              • from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file

              What command I did?



              • from 'testFile.py', wrote command,
                from Core.Generic-Class-Folder.targetClass import functionExecute

              • Got errors like SyntaxError: invalid syntax

              Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py file, inserted environment path and hugely worried what went wrong......



              And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!



              (sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)






              share|improve this answer




















              • 8





                Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

                – cowlinator
                Aug 23 '17 at 22:46















              17














              Just to notify here. (from a newbee, keviv22)



              Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.



              Invalid Folder namings as follows:



              • Generic-Classes-Folder

              • Generic_Classes_Folder

              valid Folder namings for above:



              • GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)

              What mistake I did:



              consider the file structure.



              Parent
              . __init__.py
              . Setup
              .. __init__.py
              .. Generic-Class-Folder
              ... __init__.py
              ... targetClass.py
              . Check
              .. __init__.py
              .. testFile.py


              What I wanted to do?



              • from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file

              What command I did?



              • from 'testFile.py', wrote command,
                from Core.Generic-Class-Folder.targetClass import functionExecute

              • Got errors like SyntaxError: invalid syntax

              Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py file, inserted environment path and hugely worried what went wrong......



              And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!



              (sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)






              share|improve this answer




















              • 8





                Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

                – cowlinator
                Aug 23 '17 at 22:46













              17












              17








              17







              Just to notify here. (from a newbee, keviv22)



              Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.



              Invalid Folder namings as follows:



              • Generic-Classes-Folder

              • Generic_Classes_Folder

              valid Folder namings for above:



              • GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)

              What mistake I did:



              consider the file structure.



              Parent
              . __init__.py
              . Setup
              .. __init__.py
              .. Generic-Class-Folder
              ... __init__.py
              ... targetClass.py
              . Check
              .. __init__.py
              .. testFile.py


              What I wanted to do?



              • from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file

              What command I did?



              • from 'testFile.py', wrote command,
                from Core.Generic-Class-Folder.targetClass import functionExecute

              • Got errors like SyntaxError: invalid syntax

              Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py file, inserted environment path and hugely worried what went wrong......



              And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!



              (sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)






              share|improve this answer















              Just to notify here. (from a newbee, keviv22)



              Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.



              Invalid Folder namings as follows:



              • Generic-Classes-Folder

              • Generic_Classes_Folder

              valid Folder namings for above:



              • GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)

              What mistake I did:



              consider the file structure.



              Parent
              . __init__.py
              . Setup
              .. __init__.py
              .. Generic-Class-Folder
              ... __init__.py
              ... targetClass.py
              . Check
              .. __init__.py
              .. testFile.py


              What I wanted to do?



              • from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file

              What command I did?



              • from 'testFile.py', wrote command,
                from Core.Generic-Class-Folder.targetClass import functionExecute

              • Got errors like SyntaxError: invalid syntax

              Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py file, inserted environment path and hugely worried what went wrong......



              And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!



              (sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 25 at 2:29









              Josnidhin

              9,06573257




              9,06573257










              answered Jan 27 '17 at 12:04









              Vivek22Vivek22

              369414




              369414







              • 8





                Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

                – cowlinator
                Aug 23 '17 at 22:46












              • 8





                Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

                – cowlinator
                Aug 23 '17 at 22:46







              8




              8





              Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

              – cowlinator
              Aug 23 '17 at 22:46





              Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.

              – cowlinator
              Aug 23 '17 at 22:46











              5














              Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).



              Also you can manually add your current directory (src in your case) to pythonpath:



              import os
              import sys
              sys.path.insert(0, os.getcwd())





              share|improve this answer





























                5














                Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).



                Also you can manually add your current directory (src in your case) to pythonpath:



                import os
                import sys
                sys.path.insert(0, os.getcwd())





                share|improve this answer



























                  5












                  5








                  5







                  Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).



                  Also you can manually add your current directory (src in your case) to pythonpath:



                  import os
                  import sys
                  sys.path.insert(0, os.getcwd())





                  share|improve this answer















                  Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).



                  Also you can manually add your current directory (src in your case) to pythonpath:



                  import os
                  import sys
                  sys.path.insert(0, os.getcwd())






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 21 '12 at 16:06









                  Splat

                  743310




                  743310










                  answered Jan 21 '12 at 15:04









                  Max KamenkovMax Kamenkov

                  1,23511517




                  1,23511517





















                      1














                      Say your project is structured this way:



                      +---MyPythonProject
                      | +---.gitignore
                      | +---run.py
                      | | +---subscripts
                      | | | +---script_one.py
                      | | | +---script_two.py


                      Inside run.py, you can import scripts one and two by:



                      from subscripts import script_one as One
                      from subscripts import script_two as Two


                      Now, still inside run.py, you'll be able to call their methods with:



                      One.method_from_one(param)
                      Two.method_from_two(other_param)





                      share|improve this answer



























                        1














                        Say your project is structured this way:



                        +---MyPythonProject
                        | +---.gitignore
                        | +---run.py
                        | | +---subscripts
                        | | | +---script_one.py
                        | | | +---script_two.py


                        Inside run.py, you can import scripts one and two by:



                        from subscripts import script_one as One
                        from subscripts import script_two as Two


                        Now, still inside run.py, you'll be able to call their methods with:



                        One.method_from_one(param)
                        Two.method_from_two(other_param)





                        share|improve this answer

























                          1












                          1








                          1







                          Say your project is structured this way:



                          +---MyPythonProject
                          | +---.gitignore
                          | +---run.py
                          | | +---subscripts
                          | | | +---script_one.py
                          | | | +---script_two.py


                          Inside run.py, you can import scripts one and two by:



                          from subscripts import script_one as One
                          from subscripts import script_two as Two


                          Now, still inside run.py, you'll be able to call their methods with:



                          One.method_from_one(param)
                          Two.method_from_two(other_param)





                          share|improve this answer













                          Say your project is structured this way:



                          +---MyPythonProject
                          | +---.gitignore
                          | +---run.py
                          | | +---subscripts
                          | | | +---script_one.py
                          | | | +---script_two.py


                          Inside run.py, you can import scripts one and two by:



                          from subscripts import script_one as One
                          from subscripts import script_two as Two


                          Now, still inside run.py, you'll be able to call their methods with:



                          One.method_from_one(param)
                          Two.method_from_two(other_param)






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 25 '18 at 20:34









                          Flavio WuenscheFlavio Wuensche

                          5,14013235




                          5,14013235





















                              -2














                              Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import



                              from folder.file import Class as Class
                              import folder.file as functions





                              share|improve this answer























                              • That point is not very relevant and just a repetition.

                                – crisscross
                                Feb 7 at 15:16
















                              -2














                              Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import



                              from folder.file import Class as Class
                              import folder.file as functions





                              share|improve this answer























                              • That point is not very relevant and just a repetition.

                                – crisscross
                                Feb 7 at 15:16














                              -2












                              -2








                              -2







                              Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import



                              from folder.file import Class as Class
                              import folder.file as functions





                              share|improve this answer













                              Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import



                              from folder.file import Class as Class
                              import folder.file as functions






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Dec 21 '18 at 3:00









                              Tomas TrdlaTomas Trdla

                              215




                              215












                              • That point is not very relevant and just a repetition.

                                – crisscross
                                Feb 7 at 15:16


















                              • That point is not very relevant and just a repetition.

                                – crisscross
                                Feb 7 at 15:16

















                              That point is not very relevant and just a repetition.

                              – crisscross
                              Feb 7 at 15:16






                              That point is not very relevant and just a repetition.

                              – crisscross
                              Feb 7 at 15:16


















                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8953844%2fimport-module-from-subfolder%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현