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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:46:05+00:00 2026-06-14T11:46:05+00:00

I am , as of now, simply trying to get this example given in

  • 0

I am , as of now, simply trying to get this example given in the python docs for embedding a python module in C to work. My problem is I can’t figure out where to put the python script. My ultimate goal is to have a full python package (folder with a __init__.py and various modules) to be loadable in C by executing PyImport_Import(...). But for now, please just let me know where to put the script shown (filename, path, etc) so that the C program given will run.

EDIT

I should point out what I’ve tried. I have tried putting a multiply.py file in the local directory, as well as putting it in a subdirectory called multiply in an __init__.py file. In all of these cases, I get ImportError: No module named multiply

  • 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-14T11:46:06+00:00Added an answer on June 14, 2026 at 11:46 am

    I think it should be in the same directory or in sys.path as it loads a module by name, this should work:

    ./call multiply multiply 5 6
    

    Update: if I add the current directory explicitly to sys.path it works:

    Py_Initialize();
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append(\".\")");
    

    And this prints:

    ./call multiply multiply 5 6
    ('Will compute', 5, 'times', 6)
    Result of call: 30
    

    Update: I’ve asked a relevant question and it seems that if you just add PySys_SetArgv instead it works:

    Py_Initialize();
    PySys_SetArgv(argc, argv);
    

    The reason is mentioned here:

    Otherwise (that is, if argc is 0 or argv[0] doesn’t point to an
    existing file name), an empty string is prepended to sys.path, which
    is the same as prepending the current working directory (“.”)

    And this is the question you can check the answers there too:

    Why does PyImport_Import fail to load a module from the current directory?

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

Sidebar

Related Questions

I have been trying to get this working for a while now and am
I've been struggling with this for a couple of hours now and I simply
I am learning EJB and I am trying to execute the Helloworld example given
I am stuck for 3 days now trying to get 2 google gadgets to
I'm developing an IE8+ BHO plugin. For now I'm simply trying to insert a
I'm trying to develop a pretty simple (for now) wrapper class around int ,
I am now trying to implement a simple HTML webpage scraper using Java.Now I
I'm trying to write a simple PHP MVC framework to play with. Right now,
I'm new in objective-c, and I'm now trying to write a simple user-sign-in program
right now i am simply ftping everything (all of my source code included) but

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.