Python circular issues with 'collection' numpy and matplotlib

37 Views Asked by At

I have these errors when entering debug mode with Windows 10 python 3.10 Pycharm 2022.2.1 and numpy 1.26.4 however it only seems to occur with this particular script and not other in the same venv. If I run the program the error doesn't appear but doesn't run as expected (this code be errors with my code or the following issues: start of code:

#   Generate analogue output voltage and monitor analogue voltage signal
import numpy as np
import matplotlib.pyplot as graph
import nidaqmx
from nidaqmx.stream_readers import AnalogMultiChannelReader
from nidaqmx import constants
import time
import math as maths
import datetime

errors in debug:

Error processing line 1 of C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\_virtualenv.pth:

Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 186, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\_virtualenv.py", line 40, in <module>
    from functools import partial
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\functools.py", line 18, in <module>
    from collections import namedtuple
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\Lib\site-packages\matplotlib\collections.py", line 17, in <module>
    import numpy as np
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\__init__.py", line 144, in <module>
    from numpy.__config__ import show as show_config
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\__config__.py", line 4, in <module>
    from numpy.core._multiarray_umath import (
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
    from . import overrides
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\core\overrides.py", line 80, in <module>
    ArgSpec = collections.namedtuple('ArgSpec', 'args varargs keywords defaults')
AttributeError: partially initialized module 'collections' has no attribute 'namedtuple' (most likely due to a circular import)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\core\multiarray.py", line 9, in <module>
    import functools
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\functools.py", line 18, in <module>
    from collections import namedtuple
ImportError: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\Lib\site-packages\matplotlib\collections.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 617, in <module>
    main()
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 600, in main
    known_paths = venv(known_paths)
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 532, in venv
    addsitepackages(known_paths, [sys.prefix])
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 387, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 226, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\site.py", line 196, in addpackage
    import traceback
  File "C:\Users\alexl\AppData\Local\Programs\Python\Python310\lib\traceback.py", line 3, in <module>
    import collections
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\Lib\site-packages\matplotlib\collections.py", line 17, in <module>
    import numpy as np
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\__init__.py", line 158, in <module>
    from . import core
  File "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\lib\site-packages\numpy\core\__init__.py", line 50, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\Scripts\python.exe"
  * The NumPy version is: "1.26.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: cannot import name 'namedtuple' from partially initialized module 'collections' (most likely due to a circular import) (C:\ProgramData\PycharmProjects\pythonTemperatureControl\venv\Lib\site-packages\matplotlib\collections.py)


Extension modules: numpy.core._multiarray_umath (total: 1) 

I have uninstalled and reinstalled matplotlib, nidaqmx, and numpy several times with no effect. I have no issues with matplotlib or numpy in other code in same venv.

0

There are 0 best solutions below