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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:02:55+00:00 2026-06-15T21:02:55+00:00

I have python project that runs on multiple machines. I am using virtualenv to

  • 0

I have python project that runs on multiple machines. I am using virtualenv to sync the python modules across the multiple machines. This works great. However I am pulling in some in-house baked SWIG *.so’s packages into the env as well. These c++ shared objects have some far-reaching dependency nightmares which are difficult to reproduce on some of the machines. I don’t need there code-functionality on a few of the devel machines. I would like have to rest of the python code load and continue rocking on without modification.

I would like to ‘fake-the-module’ loading on machines that dont have the modules. I wont be calling the code that actually exercises the SWIG *.so’s methods.

example:

try:
   import swigpackagefoo.swigsubpackagebar
except ImportError:
   # magic code that defines the fake module, I want to define a bunch of class'es with 'pass'
   # so all the code deps would be happy. and I dont require the swig *.so to 
   # be installed on the devel system.
   # something along the lines of.
   __import__('swigpackagefoo.swigsubpackagebar')=class foo(object): pass

Note: I think its worth noting that when the module imports the *.so, on the prod machine
the

type(swigpackagefoo)
# is 'module', also the 
type(swigpackagefoo.swigsubpackagebar)
# is also 'module'

so ‘How do I define a module-in-line’ in python?

I do not want to create the packages on the missing devel machines

i.e.: I DO-NOT want to create these files, because of module conflicts on the systems that work.

$ tree
  swigpackagefoo/__init__.py
  swigpackagefoo/swigsubpackagebar/__init__.py
  • 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-15T21:02:56+00:00Added an answer on June 15, 2026 at 9:02 pm

    If I understand you correctly, you want to be able to “mock” the compiled module if it can’t be imported?

    So if in your swigsubpackagebar you have:

    swigsubpackagebar.aFunc(aString) -> outString
    

    Then you would want a “mock” module to support that same interface, but just not do anything.

    Instead of trying to solve this with some on-the-fly module definition, just define another module that supplies the interface you want:

    ## swigMock.py ##
    def aFunc(aString):
        return aString
    

    Then structure your import statement like this:

    ## main.py ##
    try:
       import swigpackagefoo.swigsubpackagebar as swigModule
    except ImportError:
       import swigMock as swigModule
    
    print swigModule.aFunc("FOO")
    

    If swigsubpackagebar is actually a class, it’s pretty much the same concept:

    ## swigMock.py ##
    class swigsubpackagebar(object):
        pass
    

    And again use the as keyword for naming it the same:

    ## main.py ##
    try:
       import swigpackagefoo.swigsubpackagebar as swigClass
    except ImportError:
       import swigMock.swigsubpackagebar as swigClass
    
    aClass = swigClass()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a python project that we want to start testing using buildbot. Its
I have a Python project with many sub-modules that I package up with distutils.
I have a Python 3 project where I'm dynamically importing modules from disk, using
I have a project that runs Python 2.7, PyGTK 2.24, and the most recent
I have a python project that is like this : py/ main.py __init__.py myapp/
We have a project that contains a library of Python and Scala packages, as
I need to have an at-home project now that I'm working on Python/Django at
We have multiple Python projects that have dependencies on each other. Hierarchically, these are
I have a python project with this directory structure and these files: /home/project_root |---__init__.py
I'm using SQLalchemy for a Python project, and I want to have a tidy

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.