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

No module named 'capytaine.green_functions.libs.Delhommeau_float64' #395

Open
Riccardo-sus opened this issue Sep 14, 2023 · 13 comments
Open

Comments

@Riccardo-sus
Copy link

Riccardo-sus commented Sep 14, 2023

I downloaded the 2.0 version of Capytain and tried to run some examples inside the folder but I saw this error.
Inside the path (capytaine-green functions-libs) there is no "Delhommeau_float64" (I hope it can be helpful information)

Traceback (most recent call last):
  File "C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\docs\user_manual\examples\boat_animation.py", line 12, in <module>
    bem_solver = cpt.BEMSolver()
  File "C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\capytaine\bem\solver.py", line 47, in __init__
    self.green_function = Delhommeau() if green_function is None else green_function
  File "C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\capytaine\green_functions\delhommeau.py", line 65, in __init__
    self.fortran_core = import_module(f"capytaine.green_functions.libs.{self.fortran_core_basename}_{floating_point_precision}")
  File "C:\Users\0030562\Anaconda3\envs\DEME_simulator\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'capytaine.green_functions.libs.Delhommeau_float64'
@mancellin
Copy link
Collaborator

mancellin commented Sep 14, 2023

The error comes from missing compiled Fortran core routines. It occurs for instance when you download the source from the Github repository and run a script from this directory: when importing Capytaine, Python tries to use the content of the nearby capytaine directory but this directory is only sources and it is missing the compiled Fortran libraries.

How did you install Capytaine and how did you run the script?

@Riccardo-sus
Copy link
Author

Thanks for the readiness of your answer. I installed Capytaine as a library in a conda environment and after that, I downloaded the GitHub repository. I tried to follow the instructions I found in the library itself. I do not understand what are the Fortran routines that I am missing. How can I get them?

@mancellin
Copy link
Collaborator

mancellin commented Sep 15, 2023 via email

@Riccardo-sus
Copy link
Author

Indeed, I am running the scripts inside the directory downloaded from Github.
I was thinking of using this repository because inside there are instructions explaining how everything works.

So, are you advising me to create a new project and paste the scripts (inside Example folders) to make them run?

@Riccardo-sus
Copy link
Author

Riccardo-sus commented Sep 15, 2023

_______________________________________________________ ERROR collecting pytest/test_bem_green_functions.py _______________________________________________________ 
ImportError while importing test module 'C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\pytest\test_bem_green_functions.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
pytest\test_bem_green_functions.py:69: in <module>
    cpt.Delhommeau(tabulation_nr=328, tabulation_nz=46, tabulation_nb_integration_points=251),
capytaine\green_functions\delhommeau.py:65: in __init__
    self.fortran_core = import_module(f"capytaine.green_functions.libs.{self.fortran_core_basename}_{floating_point_precision}")
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'capytaine.green_functions.libs.Delhommeau_float64'
_______________________________________________ ERROR collecting pytest/test_bem_hierarchical_toeplitz_matrices.py ________________________________________________ 
ImportError while importing test module 'C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\pytest\test_bem_hierarchical_toeplitz_matrices.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
pytest\test_bem_hierarchical_toeplitz_matrices.py:25: in <module>
    solver_with_sym = cpt.BEMSolver(engine=cpt.HierarchicalToeplitzMatrixEngine(ACA_distance=8, matrix_cache_size=0))
capytaine\bem\solver.py:47: in __init__
    self.green_function = Delhommeau() if green_function is None else green_function
capytaine\green_functions\delhommeau.py:65: in __init__
    self.fortran_core = import_module(f"capytaine.green_functions.libs.{self.fortran_core_basename}_{floating_point_precision}")
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'capytaine.green_functions.libs.Delhommeau_float64'
_________________________________________________ ERROR collecting pytest/test_bem_linear_combination_of_dofs.py __________________________________________________ 
ImportError while importing test module 'C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\pytest\test_bem_linear_combination_of_dofs.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
pytest\test_bem_linear_combination_of_dofs.py:7: in <module>
    solver = cpt.BEMSolver()
capytaine\bem\solver.py:47: in __init__
    self.green_function = Delhommeau() if green_function is None else green_function
capytaine\green_functions\delhommeau.py:65: in __init__
    self.fortran_core = import_module(f"capytaine.green_functions.libs.{self.fortran_core_basename}_{floating_point_precision}")
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'capytaine.green_functions.libs.Delhommeau_float64'
____________________________________________________ ERROR collecting pytest/test_bem_problems_and_results.py _____________________________________________________ 
ImportError while importing test module 'C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\pytest\test_bem_problems_and_results.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
pytest\test_bem_problems_and_results.py:27: in <module>
    solver = cpt.BEMSolver()
capytaine\bem\solver.py:47: in __init__
    self.green_function = Delhommeau() if green_function is None else green_function
capytaine\green_functions\delhommeau.py:65: in __init__
    self.fortran_core = import_module(f"capytaine.green_functions.libs.{self.fortran_core_basename}_{floating_point_precision}")
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'capytaine.green_functions.libs.Delhommeau_float64'
____________________________________________________ ERROR collecting pytest/test_consistency_with_Nemoh_2.py _____________________________________________________ 
ImportError while importing test module 'C:\Users\0030562\Anaconda3\envs\DEME_simulator\capytaine-2.0\pytest\test_consistency_with_Nemoh_2.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
pytest\test_consistency_with_Nemoh_2.py:17: in <module>
    solver = cpt.BEMSolver(engine=cpt.BasicMatrixEngine(matrix_cache_size=0))
capytaine\bem\solver.py:47: in __init__
    self.green_function = Delhommeau() if green_function is None else green_function
capytaine\green_functions\delhommeau.py:65: in __init__
    self.fortran_core = import_module(f"capytaine.green_functions.libs.{self.fortran_core_basename}_{floating_point_precision}")
..\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'capytaine.green_functions.libs.Delhommeau_float64'
===================================================================== short test summary info ===================================================================== 
ERROR pytest/test_bem_green_functions.py
ERROR pytest/test_bem_hierarchical_toeplitz_matrices.py
ERROR pytest/test_bem_linear_combination_of_dofs.py
ERROR pytest/test_bem_problems_and_results.py
ERROR pytest/test_consistency_with_Nemoh_2.py

This is the error I am finding.

@mancellin
Copy link
Collaborator

So, are you advising me to create a new project and paste the scripts (inside Example folders) to make them run?

Yes.

This is the error I am finding.

This is the same error as above, but when trying to run the test suite with pytest. What did you try to do?

@Riccardo-sus
Copy link
Author

Basically, I have taken a copy of the git hub repository and pasted it there changing the name to Capytaine_Hydro:
C:\Users\0030562\PycharmProjects\Capytaine_Hydro
The environment instead is in another folder related to Anaconda environments:
C:\Users\0030562\Anaconda3\envs\DEME_simulator (Should I copy and paste the GitHub repository there? )

I work with Pycharm and I open the Capytaine_Hydro folder to run the tests using the environment from Anaconda.
Is it possible that I have to select the folder (cd Capytaine) in which is present the script before running it? Can be this the problem?

@mancellin
Copy link
Collaborator

Could you try creating a new Pycharm project, without the Github repository, and associate it with the conda environment in which Capytaine is installed? Then create a new file, for instance with the code below and run it.

import capytaine
print(capytaine.__version__)

Does it works?

The issue is when the Github repository is in your Pycharm project (wherever it is). Then Python is confused because there are two capytaine: one is the "capytaine" directory in the Github repository and the other one is the package in the conda environment.

@Riccardo-sus
Copy link
Author

I received this answer:

C:\Users\0030562\Anaconda3\envs\DEME_simulator\python.exe C:\Users\0030562\PycharmProjects\Hydrodynamic_sim\Test.py
2.0

Process finished with exit code 0

Therefore, I think indeed the problem is what you have said. But what do you think if I change the names of all the folders from GitHub containing Capytaine in their name? Otherwise, how can I see some examples running?

@Riccardo-sus
Copy link
Author

Thanks a lot :)

@mancellin
Copy link
Collaborator

But what do you think if I change the names of all the folders from GitHub containing Capytaine in their name? Otherwise, how can I see some examples running?

Renaming just the "capytaine" folder at the top of the Github repository might work.

Otherwise, just copy one of the example file into your new Pycharm project. The examples are meant to work independently from anywhere as long as you have Capytaine installed in the environment of your project.

@mancellin mancellin changed the title Capytain running No module named 'capytaine.green_functions.libs.Delhommeau_float64' Sep 15, 2023
@mancellin
Copy link
Collaborator

This issue could be avoided for future users by switching to an src layout instead of the current flat layout. Since Capytaine cannot run without some compilation phase anyway, the flat layout offers no advantage. It just stays there because of legacy.

@mancellin
Copy link
Collaborator

Learned recently that the -P option of recent versions of Python makes Python ignore the local modules.

python -P my_script.py

will not use the local capytaine directory.

@mancellin mancellin pinned this issue Mar 18, 2024
@mancellin mancellin unpinned this issue Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants