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 7800467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:38:52+00:00 2026-06-02T00:38:52+00:00

I have a module foo, containing util.py and bar.py. I want to import it

  • 0

I have a module foo, containing util.py and bar.py.

I want to import it in IDLE or python session. How do I go about this?

I could find no documentation on how to import modules not in the current directory or the default python PATH.
After trying import "<full path>/foo/util.py",
and from "<full path>" import util

The closest I could get was

import imp
imp.load_source('foo.util','C:/.../dir/dir2/foo')

Which gave me Permission denied on windows 7.

  • 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-02T00:38:54+00:00Added an answer on June 2, 2026 at 12:38 am

    One way is to simply amend your path:

    import sys
    sys.path.append('C:/full/path')
    from foo import util,bar
    

    Note that this requires foo to be a python package, i.e. contain a __init__.py file. If you don’t want to modify sys.path, you can also modify the PYTHONPATH environment variable or install the module on your system. Beware that this means that other directories or .py files in that directory may be loaded inadvertently.

    Therefore, you may want to use imp.load_source instead. It needs the filename, not a directory (to a file which the current user is allowed to read):

    import imp
    util = imp.load_source('util', 'C:/full/path/foo/util.py')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this in initializers in rails (config/initializers/foo.rb) module foo module bar def
If I have Foo::Bar written in Ruby, and I want to add a method
I have an ivy.xml containing <dependencies> <dependency org=commons-lang name=commons-lang rev=2.4/> <dependency org=foo-bar name=superwidgets rev=1.5/>
Say I have a package called Foo organized this way: Foo\ __init__.py foo.py bar.py
I have a simple class that defines some constants, e.g.: module Foo class Bar
If I have a module, foo , in Lib/site-packages , I can just import
I have a maven project with a module /myProject pom.xml /myModule pom.xml /foo bar.txt
Situation: I have a module Foo::Quux::Bar , living in ./Bar.pm . I need to
Can someone explain to me what this would do? Module Foo class Bar class_inheritable_accessor
In python, If I have a class foo , I can call foo.__module__ to

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.