4

I’m using conda-pack to create relocatable miniconda environments on Windows (Windows 10, 64 bit, Python 3.8). It works great: I can activate the environment on the target machine using

activate base

and run python with all the conda goodies inside.

Now I compile a DLL written in C that embeds the relocated environment. It works – as long as I don’t try to use conda-specific functions (such as import numpy) – in that case, PyImport_Import(pName) returns NULL (pName = "python38.dll" in my case). The problem is obviously that the environment has not been activated correctly.

What I already tried looking at posts elsewhere:

  • Set up PATH, PYTHONHOME environment variables in Windows to point all binary directories of the env (works in a DOS shell, not embedded)

  • Use Py_SetPythonHome(program_name) and Py_SetProgramName() with the absolute path to the root of the env, hoping that would activate it

  • Use Py_SetPath(path) with a comma-separated list of all absolute paths of env’s binary directories (c:\root; c:\root\Lib; c:\root\Scripts;c:\root\DLLs)

Did anyone successfully use such an embedded conda environment from C?

Thanks for any ideas!

Werner

werner
  • 377
  • 2
  • 10
  • After some more investigation, running in a DLL seems to be the problem. While it works in an EXE, the same code crashes in PyImport_ImportModule("numpy") when running in a DLL... – werner Aug 20 '21 at 07:33

0 Answers0