petercorke / robotics-toolbox-python

Robotics Toolbox for Python
MIT License
1.99k stars 420 forks source link

Import Error: randn from scripy #412

Open NicholasSnyder opened 6 months ago

NicholasSnyder commented 6 months ago

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.

Screenshots image

Environment

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.

kingjin94 commented 6 months ago

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.

FelipeCybis commented 6 months ago

It turns out the scipy.randn function was not even used by robotics-toolbox-python. I created a PR to fix this.

WendaXu2023 commented 5 months ago

I meet the same problem. Is it fixed?

wanglong06 commented 5 months ago

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!

JakobDomislovic commented 4 months ago

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

daironxuan commented 4 months ago

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
pappuyadav commented 2 months ago

I meet the same problem. Is it fixed?

https://github.com/petercorke/robotics-toolbox-python/issues/436