question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scipy.signal doesn't allow for user modules to be named `constants`

See original GitHub issue

If you have a module named constants in your project, then if you try to use that module while at the same time using scipy.signal (and it seems any module that uses scipy.optimize), you’ll get an exception. It seems to be related to https://github.com/scipy/scipy/blame/master/scipy/optimize/_highs/cython/src/constants.pyx

Reproducing code example:

#!/bin/sh

# Don't run this in a place where you have an existing file named `constants.py`
echo "MY_IMPORTANT_CONSTANT = 1" > constants.py
python3 -c "from scipy import signal; import constants; print(constants.MY_IMPORTANT_CONSTANT)"
rm constants.py

Error message:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
AttributeError: module 'scipy.optimize._highs.constants' has no attribute 'MY_IMPORTANT_CONSTANT'

Scipy/Numpy/Python version information:

1.6.0 1.19.4 sys.version_info(major=3, minor=9, micro=1, releaselevel='final', serial=0)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
153957commented, Jan 5, 2021

We encountered the same issue. We resolved it by renaming our constants module to something else (which was fine, we did not like the name anyway), but it is an annoying bug.

0reactions
mikemikezhucommented, Jan 26, 2021

Also encountered same issue when importing the constants module

ImportError: cannot import name 'IMAGE_NET_DISPLAY_ROW' from 'scipy.optimize._highs.constants'

Need to work around the issue by renaming the constants module in the project

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'module' object (scipy) has no attribute 'misc'
AttributeError: 'module' object (scipy) has no attribute 'misc' ; I found an equivalent function pylab.imsave which works. – moadeep. Nov 27, 2012 at...
Read more >
scipy.optimize.curve_fit — SciPy v1.9.3 Manual
The method 'lm' won't work when the number of observations is less than the number of variables, use 'trf' or 'dogbox' in this...
Read more >
scipy.optimize.least_squares — SciPy v1.9.3 Manual
Solve a nonlinear least-squares problem with bounds on the variables. Given the residuals f(x) (an m-D real function of n real variables) and...
Read more >
SciPy 1.8.0 Release Notes — SciPy v1.9.3 Manual
Before upgrading, we recommend that users check that their own code does not use deprecated SciPy functionality (to do so, run your code...
Read more >
SciPy API — SciPy v1.9.3 Manual
If a module or package doesn't define __all__ , then all names that don't ... User-visible functions should have good documentation following the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found