cannot import from partially initialized module 'noise'

Viewed 502

I have the current 'noise' package 2.2 in python3.8 It appears to have a circular import problem; I do not believe I have any similarly named files in my own folders. My code: import noise

Result>

    import noise
  File "C:\Python\Python38\lib\site-packages\noise\__init__.py", line 12, in 
    from . import _perlin, _simplex
ImportError: cannot import name '_perlin' from partially initialized module 'noise' (most likely due to a circular import) (C:\Python\Python38\lib\site-packages\noise\__init__.py)
1 Answers

From a Github issue regarding this problem:

What's happening is that Python prefers to look for modules in relative paths before absolute paths. Since you can import noise from the repo directory, that means it's probably already in your python path(an absolute path).

Say this repository lives in foo/noise/ and now you are in foo/ if you go up a directory and try to run import noise. Python will see that the local directory noise/ as a module because it has an init.py file and try to import the directory instead of the module installed in your python path. Since this module requires the _noise and _simplex C extensions to be compiled, this wont work.

I'd recommend removing or renaming this repo directory from your project and use pip to install noise if you haven't already. (pip install noise)

If you really want to install from source and not install into your system, then, in the noise/ repository, run python setup.py build to build locally and grab dist/lib*/noise/ and put that directory into your project directory.

Alternatively use python setup.py install in the noise/ repository to install from source into your Python path.

Related