Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enable support for editable dependencies #2593

Open
@iFreilicht

Description

@iFreilicht

When installing editable dependencies with pip or other python package managers into a virtualenv, they end up insite-packages as.pth files which contain the actual absolute path of the package.

Usually, python is able to follow these as if they were symlinks and import packages that were installed that way. However, this doesn't seem to work with Python.NET. I just get an error inPy.Import:

An exception of type 'Python.Runtime.PythonException' occurred in Python.Runtime but was not handled in user code: 'No module named 'mymodule''

I do have a workaround for this, which is just to read all the.pth files and add those paths to PYTHONPATH manually, but it would be much nicer if this could just work out of the box.

stringvirtualEnvPath=$@".\myDir\.venv";stringvenvSitePackagesPath=$@"{sVirtualEnvPath}\Lib\site-packages";// Resolve editable dependencies manually because Python.NET doesn't do sostring[]editableDependencyReferences=Directory.GetFiles(venvSitePackagesPath,"*.pth");string[]editableDependencyPaths=editableDependencyReferences.Select(filePath=>File.ReadAllText(filePath).Trim()).ToArray();stringpythonPath=$"{venvSitePackagesPath};"+@"C:\Program Files\Python312\Lib;"+@"C:\Program Files\Python312\DLLs;"+string.Join(";",editableDependencyPaths);// Add them to the pathEnvironment.SetEnvironmentVariable("PATH",Environment.GetEnvironmentVariable("PATH").TrimEnd(';')+";"+virtualEnvPath,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PYTHONHOME",virtualEnvPath,EnvironmentVariableTarget.Process);Environment.SetEnvironmentVariable("PYTHONPATH",pythonPath,EnvironmentVariableTarget.Process);PythonEngine.PythonHome=virtualEnvPath;PythonEngine.PythonPath=pythonPath;PythonEngine.Initialize();using(Py.GIL()){dynamicmymodule=Py.Import("mymodule");// Succeeds now!}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp