GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

The example_clustering_2.py not working

Open KelvinChung2000 opened this issue 2 years ago • 7 comments

I have installed PYGAD with pip and tried to run the example_clustering_2.py and it gives the following error:

  File "/home/GeneticAlgorithmPython/example_clustering_2.py", line 3, in <module>
    import pygad
  File "/home/GeneticAlgorithmPython/pygad.py", line 9, in <module>
    from pygad import utils
ImportError: cannot import name 'utils' from partially initialized module 'pygad' (most likely due to a circular import) (/home/GeneticAlgorithmPython/pygad.py)

KelvinChung2000 avatar Apr 21 '23 10:04 KelvinChung2000

Please consider installing PyGAD using pip if not already installed.

Then run the example_clustering_2.py script outside of the cloned repository directory. It imports the pygad.py module in this directory.

ahmedfgad avatar Apr 21 '23 10:04 ahmedfgad

Thanks a lot, I have got it working when using standard pip install. However, when I install it from the git repo using pip install -e . the same error pops up.

KelvinChung2000 avatar Apr 21 '23 10:04 KelvinChung2000

The GitHub repository does not have the complete package. We are working in to have all the modules in the library in another branch before merging it. At the moment, the modules are split into multiple repositories.

Moreover, even running the example_clustering_2.py script in a folder containing the pygad.py module, the same issue will rise. This is because Python searches for the module in the same folder first. If found, then it uses it and will not use the installed library in the site-packages folder.

The way it works is by installing the library using pip install --upgrade pygad and the script will definitely work.

ahmedfgad avatar Apr 22 '23 14:04 ahmedfgad

Sure, I will wait for the release than. I need to install it with the git repo since I need to work on a optimization with a complex data structure that cannot be done with an Numpy array. I need to modify the file to do what I need to do.

KelvinChung2000 avatar Apr 22 '23 15:04 KelvinChung2000

You can still modify the code locally after installing the library using pip.

Just locate the installation directory in the site-packages folder. Then edit the code.

ahmedfgad avatar Apr 26 '23 03:04 ahmedfgad

This is not recommended, but this will do for now. Thanks a lot. By the way, would you be interested in improving the formatting of the code and including typing to the library? I am happy to contribute if you are interested.

KelvinChung2000 avatar Apr 26 '23 10:04 KelvinChung2000

You are completely welcome to contribute. Just create a pull request of your contributions. Thanks a lot.

ahmedfgad avatar Apr 26 '23 11:04 ahmedfgad