Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SofaPython3 plugin on Windows #159

Closed
CorentinLanguepin opened this issue Jul 29, 2021 · 0 comments · Fixed by #190
Closed

Adding SofaPython3 plugin on Windows #159

CorentinLanguepin opened this issue Jul 29, 2021 · 0 comments · Fixed by #190
Assignees

Comments

@CorentinLanguepin
Copy link

I built Sofa on Windows (I took the master branch for the Sofa sources) and I tried to add the SofaPython3 plugin. When I tried via the Plugin Manager, this warning appeared on my terminal and Sofa crashed :

[WARNING] [PythonEnvironment] No python dir found in E:/sofa/build/bin

Indeed, the plugin is in the folder : E:/sofa/build/bin/Release and with the help of Damien, we saw that the problem came from the following function in PythonEnvironment.cpp :

void PythonEnvironment::addPythonModulePathsForPluginsByName(const std::string& pluginName)
{
    std::map<std::string, Plugin>& map = PluginManager::getInstance().getPluginMap();
    for( const auto& elem : map)
    {
        Plugin p = elem.second;
        if ( p.getModuleName() == pluginName )
        {
            std::string pluginLibraryPath = elem.first;
            // moduleRoot should be 2 levels above the library (plugin_name/lib/plugin_name.so)
            std::string moduleRoot = FileSystem::getParentDirectory(FileSystem::getParentDirectory(pluginLibraryPath));
            addPythonModulePathsForPlugins(moduleRoot);
            return;
        }
    }
    msg_warning("PythonEnvironment") << pluginName << " not found in PluginManager's map.";
}

It seems logical to have this warning because the function uses twice getParentDirectory and as a consequence, from E:/sofa/build/bin/Release/SofaPython3.dll we go to E:/sofa/build/bin, where there is no python3 dir.

We changed the source code and more precisely the file PythonEnvironment.cpp by adding a third getParentDirectory. Thus the line is now :

std::string moduleRoot = FileSystem::getParentDirectory(FileSystem::getParentDirectory(FileSystem::getParentDirectory(pluginLibraryPath)));

With that in mind, we added a PYTHONPATH like this : E:/sofa/build/python3/site-packages. With those changes, it seems to work but my question is : is this an error from the source code to not be able to add the plugin from the plugin manager, or is this more a problem with CMake with a Windows distribution that put some files or folders in a place where it should not be during the compilation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants