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

PyNomad Import Error in Python>3.6 #151

Open
juavid opened this issue Sep 21, 2023 · 7 comments
Open

PyNomad Import Error in Python>3.6 #151

juavid opened this issue Sep 21, 2023 · 7 comments

Comments

@juavid
Copy link

juavid commented Sep 21, 2023

I have tested PyNomad successfully with Python 3.6 but when I try to install it in Python version >3.6 I get the following error after installing it when trying to import the PyNomad library.

import PyNomad
ImportError: DLL load failed while importing PyNomad: The specified module could not be found.

Is there is any workaround to make it work in Python version >3.6?

Thanks in advanced.

@juavid juavid changed the title PyNomad Import Error in Python3.8 PyNomad Import Error in Python>3.6 Sep 21, 2023
@ctribes
Copy link
Contributor

ctribes commented Sep 21, 2023

It should work with Python version > 3.6. Nothing special is required.

Something that can go wrong is the path where Nomad libraries are located. Here are some checks that I did on my computer. Please note, the last element in the %PATH% variable, this is where the Nomad libraries have been put when building with mingw tools (it will be different for Visual Studio).

image

@ctribes
Copy link
Contributor

ctribes commented Sep 27, 2023

There are several tricky things when building/import PyNomad. One is the compatibility between the compiler and the Python version. For example, in my case (OSX), I have

(base) christophe@Fol-de-Dol nomad4dev_Copy2 % python
Python 3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

So I need to build nomad with Clang. But the right architecture must be selected ('arm64' or 'x86_64'). I can force x86_64 by adding a build flag like -DCMAKE_OSX_ARCHITECTURES=x86_64 when configuring with cmake.

@ctribes
Copy link
Contributor

ctribes commented Sep 27, 2023

When importing PyNomad in Python is not working another option exists.

Nomad can optimize on a Python blackbox without using the PyNomad interface in batch mode (see user guide).
A simple example is provided.

param.txt

bb.py

import sys
import os
import re
input_file_name=sys.argv[1]
with open(input_file_name,'r') as openfile:
    line = openfile.read().strip()
    X = re.sub('\s+',' ',line).strip().split()
    openfile.close()

dim = 5
f = float(X[4])
g1 = sum([(float(X[i])-1)**2 for i in range(dim)])-25
g2 = 25-sum([(float(X[i])+1)**2 for i in range(dim)])
print(f,g1,g2)

@juavid
Copy link
Author

juavid commented Sep 27, 2023

That is a good solution, thanks for the help, I have tried with VS17 and VS16 and two different PCs. I identified at least one potential problem related to setuptools>60.0.0. but even then the problem remains. There are some warning messages as well during the compilation but they seem to also appear when I compile it for python 3.6. I was wondering what would be the recommended compiler for Windows?

@ctribes
Copy link
Contributor

ctribes commented Sep 27, 2023

Visual Studio 15 works for me when building PyNomad.
I tried with MinGW and it is not working as is.

@juavid juavid closed this as completed Sep 28, 2023
@juavid juavid reopened this Sep 28, 2023
@nic-ian
Copy link

nic-ian commented Nov 25, 2023

Has someone found the causes of this problem? I am using Visual Studio 2022 as a complier, and Python 3.10.12. It produces this error message when importing PyNomad from Python. I used DependenciesGUI to find the missing DLL but no one of them seems missing. The path should be correct since i can correctly call nomad from my CMD.

Furthermore, I checked the architecture and it is correct AMD64, both in the .pyd and in my computer

Thank you in advance!

@ctribes
Copy link
Contributor

ctribes commented Jan 9, 2024

The building procedure has changed for release v.4.4.0. Maybe it can help solving the problem.
Also, PyNomad binaries are now available at https://pypi.org/project/PyNomadBBO/

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

No branches or pull requests

3 participants