Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not import pysindy after installation #529

Closed
xinchen236 opened this issue Jul 11, 2024 · 8 comments · Fixed by #543
Closed

Can not import pysindy after installation #529

xinchen236 opened this issue Jul 11, 2024 · 8 comments · Fixed by #543

Comments

@xinchen236
Copy link

xinchen236 commented Jul 11, 2024

I installed pysindy from a local copy, and it shows a successful installation. But when I tried to import the package on Python, an error came out as "NameError: name 'cp' is not defined". The details are attached below. Can anyone help me with this issue? Many thanks!

NameError Traceback (most recent call last)
Cell In[5], line 1
----> 1 import pysindy as ps
cost = cp.sum_squares(x_expanded @ xi - y.flatten())

NameError: name 'cp' is not defined

@xinchen236
Copy link
Author

Problem solved. Need to install "cvxpy" first.

@Jacob-Stevens-Haas
Copy link
Collaborator

Jacob-Stevens-Haas commented Jul 11, 2024

No, this is an issue. cvxpy is an optional dependency, and it shouldn't block importing pysindy. (It should block using ConstrainedSR3, however).

the file likely needs a from __future__ import annotations line at the top.

What's your pysindy version?

@talitta-nunes
Copy link

I had a similar problem, but it's causing the error below. I like to test using Google Colab, I never had any trouble until today! I tried to remove the derivative package, install the correct version of the importlib_metadata and run again, but unsuccessful. So I had to use the virtual environment to deal with and make it work

ContextualVersionConflict                 Traceback (most recent call last)
<ipython-input-24-a39643098e1c> in <cell line: 1>()
----> 1 import pysindy as ps
      2 import numpy as np
      3 import pandas as pd
      4 import math
      5 import matplotlib.pyplot as plt

5 frames
/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py in _resolve_dist(self, req, best, replace_conflicting, env, installer, required_by, to_activate)
    871             # Oops, the "best" so far conflicts with a dependency
    872             dependent_req = required_by[req]
--> 873             raise VersionConflict(dist, req).with_context(dependent_req)
    874         return dist
    875 

ContextualVersionConflict: (importlib-metadata 8.0.0 (/usr/local/lib/python3.10/dist-packages), Requirement.parse('importlib-metadata<8.0.0,>=7.1.0'), {'derivative'})```

@Jacob-Stevens-Haas
Copy link
Collaborator

Jacob-Stevens-Haas commented Jul 12, 2024

Hi Talitta, I'm not sure what you were trying to to accomplish that prompted this error, but using a virtual environment is normal practice to prevent version conflicts. I'm not familiar with google's installation package management system, however.

It appears you have a conflict because pysindy requires derivative, and derivative requires importlib-metadata <8.0.0, but something else requires importlib-metadata >= 8.0.0.

@azhartman79

This comment was marked as duplicate.

@Jacob-Stevens-Haas
Copy link
Collaborator

Jacob-Stevens-Haas commented Jul 22, 2024

For those with the importlib-metadata conflict, that's being generated by derivative - a dependency of pysindy, but it's own package. I would suggest positing the issue there.

@lunassneu
Copy link

The same thing happened to me. I installed Sindy directly from the git repository, I use Windows, Anaconda.
the installation was successful, but when I import sindy this error message appears about cp:

NameError Traceback (most recent call last)
Cell In[3], line 1
----> 1 import pysindy as ps

File D:\Program Files\anaconda3\Lib\site-packages\pysindy_init_.py:11
9 from . import differentiation
10 from . import feature_library
---> 11 from . import optimizers
12 from . import deeptime
13 from . import utils

File D:\Program Files\anaconda3\Lib\site-packages\pysindy\optimizers_init_.py:3
1 from .base import BaseOptimizer
2 from .base import EnsembleOptimizer
----> 3 from .constrained_sr3 import ConstrainedSR3
4 from .frols import FROLS
6 try: # Waiting on PEP 690 to lazy import gurobipy

File D:\Program Files\anaconda3\Lib\site-packages\pysindy\optimizers\constrained_sr3.py:22
18 from ..utils import reorder_constraints
19 from .sr3 import SR3
---> 22 class ConstrainedSR3(SR3):
23 """
24 Sparse relaxed regularized regression with linear (in)equality constraints.
25
(...)
152 may increase and decrease as the algorithm works.
153 """
155 def init(
156 self,
157 threshold=0.1,
(...)
176 unbias=False,
177 ):

File D:\Program Files\anaconda3\Lib\site-packages\pysindy\optimizers\constrained_sr3.py:276, in ConstrainedSR3()
271 rhs = rhs.reshape(g.shape)
272 return inv1.dot(rhs)
274 def _create_var_and_part_cost(
275 self, var_len: int, x_expanded: np.ndarray, y: np.ndarray
--> 276 ) -> Tuple[cp.Variable, cp.Expression]:
277 xi = cp.Variable(var_len)
278 cost = cp.sum_squares(x_expanded @ xi - y.flatten())

NameError: name 'cp' is not defined

I didn't understand what Jacob said about from future import annotations
Where do I have to add this line of code?

@lunassneu
Copy link

No, this is an issue. cvxpy is an optional dependency, and it shouldn't block importing pysindy. (It should block using ConstrainedSR3, however).

the file likely needs a from __future__ import annotations line at the top.

What's your pysindy version?

Can you help me please? I explained the problem above

Jacob-Stevens-Haas added a commit to andgoldschmidt/derivative that referenced this issue Aug 26, 2024
This package is a backport of part of the core library in 3.10, so
is extremely stable.  It will no longer be required in a year,
when 3.9 reaches EOL.  In the meantime, it is causing plenty of
failures of pysindy installs.  See dynamicslab/pysindy#547 and
coments on dynamicslab/pysindy#529.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants