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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:57:20+00:00 2026-06-13T16:57:20+00:00

After much hair loss, I’m looking for help. I’m embedding Python 3.3 into a

  • 0

After much hair loss, I’m looking for help.

I’m embedding Python 3.3 into a simple app. One unusual aspect is Python isn’t on the path, but it all seems to load OK. But for some reason, nothing can be executed.

Below is a small example program that shows the error:

EDIT: I know the reference counting is horrible — this is just a simple example.

SetDllDirectory(L"D:\\dev\\python\\python33"); //so Python33.dll can be delay-loaded since not in the path

Py_Initialize();
PyObject* pGlobals = PyDict_New();
if (PyDict_GetItemString(pGlobals, "__builtins__") == NULL) 
{
    PyObject* pMod = PyImport_ImportModule("builtins"); <-- always succeeds
    if(NULL != pMod)
        PyDict_SetItemString(pGlobals, "__builtins__", pMod);
}

PyObject* pResult = PyRun_String("import sys", 0, pGlobals, pGlobals); <-- always fails

if (PyErr_Occurred()) 
{
    //PyErr_Fetch returns:
    //<class 'SyntaxError'>  
    //('invalid syntax', ('<string>', 1, 6, 'import sys'))
}

I have tried a variety of ways to import and define builtins, including various attempts shown below:

PyObject* pMod = PyImport_ImportModule("builtins");
PyDict_SetItemString(pGlobals, "builtins", pMod);
PyDict_SetItemString(pGlobals, "__builtins__", pMod);

PyDict_SetItemString(pGlobals, "__builtins__", PyEval_GetBuiltins());
PyDict_SetItemString(pGlobals, "builtins", PyEval_GetBuiltins());

None of them work — the error is identical with each.

What am I doing wrong? Is it path related? Something about builtins that I’m doing wrong?

  • 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-13T16:57:21+00:00Added an answer on June 13, 2026 at 4:57 pm

    Try it with the start symbol set to Py_file_input and use PyEval_GetBuiltins.

    Edit: the correct dict key to set is "__builtins__".

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

Sidebar

Related Questions

After much googling and console testing I need some help with arrays in rails.
After many hours of hair pulling, I look to stackoverflow to help me solve
After much delay, I realize I want to implement a version control system into
After much searching and trials, I am stuck... I have two classes, one is
OK, after much research, and help with stackoverflow users, I've narrowed down how to
After much looking, I found a bit of code that converts a BufferedImage to
After much reading, I realized that Zend_Form can be divided into various representations, it
After much help from all my StackOverFlow brethren, I managed to create a C++
After much google searching and looking through other posts here i still can't work
This might be a very simple question but after much searching on different forums

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.