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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:03:37+00:00 2026-06-04T00:03:37+00:00

I have two Python packages where one needs to be imported by the other.

  • 0

I have two Python packages where one needs to be imported by the other. The directory structure is like follows:

workspace/
  management/
    __init__.py
    handle_management.py
    other_management.py
  utils/
    __init__.py
    utils_dict.py

I’m trying to import functionality from the utils project in the handle_management.py file:

import utils.utils_dict

Error I’m getting when trying to run handle_management.py:

ImportError: No module named utils.utils_dict

I’ve read a lot about how to resolve this problem and I can’t seem to find a solution that works.

I started with Import a module from a relative path – I tried the applicable solutions but none worked.

Is the only solution to make workspace/ available via site_packages? If so, what is the best way to do this?

EDIT:

I’ve tried to add the /home/rico/workspace/ to the PYTHONPATH – no luck.

EDIT 2:

I was able to successfully use klobucar’s solution but I don’t think it will work as a general solution since this utility is going to be used by several other developers. I know I can use some Python generalizations to determine the relative path for each user. I just feel like there is a more elegant solution.

Ultimately this script will run via cron to execute unit testing on several Python projects. This is also going to be available to each developer to ensure integration testing during their development.

I need to be able to make this more general.

EDIT 3:

I’m sorry, but I don’t really like any of these solutions for what I’m trying to accomplish. I appreciate the input – and I’m using them as a temporary fix. As a complete fix I’m going to look into adding a script available in the site_packages directory that will add to the PYTHONPATH. This is something that is needed across several machines and several developers.

Once I build my complete solution I’ll post back here with what I did and mark it as a solution.

EDIT 4:

I feel as though I didn’t do a good job expressing my needs with this question. The answers below addressed this question well – but not my actual needs. As a result I have restructured my question in another post. I considered editing this one, but then the answers below (which would be very helpful for others) wouldn’t be meaningful to the change and would seem out of place and irrelevant.

For the revised version of this question please see Unable to import Python package universally

  • 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-04T00:03:39+00:00Added an answer on June 4, 2026 at 12:03 am

    You have 2 solutions:

    Either put workspace in your PYTHONPATH:

    import sys
    sys.path.append('/path/to/workspace')
    
    from utils import utils_dict
    

    (Note that if you’re running a script inside workspace, that is importing handle_management, most probably workspace is already in your PYTHONPATH, and you wouldn’t need to do that, but it seems it’s not the case HERE).

    Or, make “workspace” a package by adding an empty (or not) __init__.py file in the workspace directory. Then:

    from ..utils import utils_dict
    

    I would prefer the second, because you would have a problem if there’s another module called “utils” in you PYTHONPATH

    Apart from that, you are importing wrong here: import utils.utils_dict.py. You don’t need to include the extension of the file “.py”. You are not importing the file, you are importing the module (or package if it’s a folder), so you don’t want the path to that file, you need its name.

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

Sidebar

Related Questions

I have in my python workspace two Modules which need sip.pyd Module1.pyd needs sip.pyd
If I have two dictionaries I'd like to combine in Python, i.e. a =
I have two packages installed with the same name, one globally and one locally
I have two versions of python on my mac: One preinstalled by Apple in
I have a program using python's packages multiprocessing and Queue. One of my functions
I have a package with two modules in it. One is the __init__ file,
I have two Python functions, both of which take variable arguments in their function
In Python, I have two lists that either have equal number of elements (e.g.
I have written a Python module, and I have two versions: a pure Python
Possible Duplicate: Python, compute list difference I have two lists For example: A =

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.