Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:42:55+00:00 2026-06-10T19:42:55+00:00

two py file: ./src/foo.py def bar (): print ‘bar!’ ./tests/testfoo.py from foo import bar

  • 0

two py file:

./src/foo.py

def bar ():
    print 'bar!'

./tests/testfoo.py

from foo import bar
print 'testing'
bar ()

in the root folder ‘./’, calling

python ./tests/testfoo.py

the result is

Traceback (most recent call last):
  File "./tests/testfoo.py", line 1, in <module>
    from foo import bar
ImportError: No module named foo

running the testfoo.py but naturally module foo could not be found by the interpreter. can i give any parameter to interpreter to lookup modules in the folder ‘src’?

Edit #1

also added two empty init.py file.

./src/__init__.py
./tests/__init__.py

still getting the same error.

Edit #2 (Solution)

I solved problem by adding a new initialization py file

prep.py

import os, sys
cur = os.path.dirname (__file__)
pathtest = os.path.join (cur, 'tests')
sys.path.append (pathtest)

then called:

python prep.py tests/testfoo.py

it worked

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:42:57+00:00Added an answer on June 10, 2026 at 7:42 pm

    Try this:

    import sys
    sys.path.append('your/path')
    import testfoo
    

    You may need to make ./tests an absolute path…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two text file. file1.txt has: gedit google chrome git vim foo bar
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I have two csv file ( ) I can get it to print out
I have a file structure that looks something like this: project1_root/ tests/ ... src/
I have two open file objects, dest and src . File object dest is
I'm having two property file called sample.properties and sample1.properties in src folder at same
I have a c++ project having two src folders. Source file in folder 1
I have two persistence.xml files, for the sake of testing: src/main/resources/META-INF/persistence.xml src/test/resources/META-INF/persistence.xml How to
I'm trying to extract two blocks of code from a text file using Java
I have two js files, both called by one HTML file. <script type=text/javascript src=scripts/levelmovement.js></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.