Import Error: randn from scripy
NicholasSnyder opened this issue ยท 7 comments
Describe the bug
ImportError: cannot import name 'randn' from 'scipy'
Version information
installed from pip 23.2.1
To Reproduce
Steps to reproduce the behavior:
from spatialmath.base import *
from roboticstoolbox import *
OUTPUT:
Exception has occurred: ImportError
cannot import name 'randn' from 'scipy' (C:\Users\Nicholas Snyder\AppData\Local\Programs\Python\Python312\Lib\site-packages\scipy_init_.py)
File "C:\Users\Nicholas Snyder\Downloads\RVC3-python-main\test.py", line 2, in
from roboticstoolbox import *
ImportError: cannot import name 'randn' from 'scipy' (C:\Users\Nicholas Snyder\AppData\Local\Programs\Python\Python312\Lib\site-packages\scipy_init_.py)
Expected behavior
Expected toolbox to successfully import.
Environment
- Windows Version 10.0.19045 Build 19045
- Python 3.12.1 64bit
Additional context
The only thing I was able to find on this issue is that scipy does not have a random module to import anymore. A proposed alternative is to use random from numpy. However, I am not sure if this is the actual underlying issue.
Can confirm this error on Python 3.9/10/11 in the official Python containers (https://hub.docker.com/_/python). "pip install scipy<1.12.0" seems to be a viable hot fix.
It turns out the scipy.randn
function was not even used by robotics-toolbox-python
. I created a PR to fix this.
I meet the same problem. Is it fixed?
I am currently having the same problem, and currently, I confirm that @kingjin94 's proposed hot fix (scipy<1.12.0) work. But a proper fix would be greatly appreciated!
Go to roboticstoolbox/mobile/EKF.py and change that randn is imported from numpy and remove it from scipy import. Use: from numpy.random import randn
site-packages/roboticstoolbox/mobile/EKF.py:
from collections import namedtuple
import numpy as np
from math import pi
from scipy import integrate
from scipy.linalg import sqrtm, block_diag
from scipy.stats.distributions import chi2
import matplotlib.pyplot as plt
from matplotlib import animation
from spatialmath.base.animate import Animate
from spatialmath import base, SE2
from roboticstoolbox.mobile import VehicleBase
from roboticstoolbox.mobile.landmarkmap import LandmarkMap
from roboticstoolbox.mobile.sensors import SensorBase
# Use numpy's randn instead of scipy's
from numpy.random import randn
I meet the same problem. Is it fixed?