Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
2e834e3
1
Parent(s):
87b573d
Clean up ImportError
Browse files- pysr/sr.py +17 -17
pysr/sr.py
CHANGED
@@ -41,6 +41,20 @@ def install(julia_project=None): # pragma: no cover
|
|
41 |
)
|
42 |
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
Main = None
|
45 |
|
46 |
already_ran = False
|
@@ -275,13 +289,7 @@ def init_julia():
|
|
275 |
|
276 |
info = JuliaInfo.load(julia="julia")
|
277 |
if not info.is_pycall_built():
|
278 |
-
raise ImportError(
|
279 |
-
"""
|
280 |
-
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
281 |
-
|
282 |
-
>>> import pysr
|
283 |
-
>>> pysr.install()"""
|
284 |
-
)
|
285 |
|
286 |
Main = None
|
287 |
try:
|
@@ -322,7 +330,7 @@ def _write_project_file(tmp_dir):
|
|
322 |
SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
|
323 |
|
324 |
[compat]
|
325 |
-
SymbolicRegression = "0.7.
|
326 |
julia = "1.5"
|
327 |
"""
|
328 |
|
@@ -1023,15 +1031,7 @@ class PySRRegressor(BaseEstimator, RegressorMixin):
|
|
1023 |
else:
|
1024 |
Pkg.instantiate()
|
1025 |
except RuntimeError as e:
|
1026 |
-
raise ImportError(
|
1027 |
-
f"""
|
1028 |
-
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
1029 |
-
|
1030 |
-
>>> import pysr
|
1031 |
-
>>> pysr.install()
|
1032 |
-
|
1033 |
-
Tried to activate project {self.julia_project} but failed."""
|
1034 |
-
) from e
|
1035 |
Main.eval("using SymbolicRegression")
|
1036 |
|
1037 |
Main.plus = Main.eval("(+)")
|
|
|
41 |
)
|
42 |
|
43 |
|
44 |
+
def import_error_string(julia_project=None):
|
45 |
+
s = f"""
|
46 |
+
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
47 |
+
|
48 |
+
>>> import pysr
|
49 |
+
>>> pysr.install()
|
50 |
+
"""
|
51 |
+
|
52 |
+
if julia_project is not None:
|
53 |
+
s += f"""
|
54 |
+
Tried to activate project {julia_project} but failed."""
|
55 |
+
|
56 |
+
return s
|
57 |
+
|
58 |
Main = None
|
59 |
|
60 |
already_ran = False
|
|
|
289 |
|
290 |
info = JuliaInfo.load(julia="julia")
|
291 |
if not info.is_pycall_built():
|
292 |
+
raise ImportError(import_error_string())
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
Main = None
|
295 |
try:
|
|
|
330 |
SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
|
331 |
|
332 |
[compat]
|
333 |
+
SymbolicRegression = "0.7.4"
|
334 |
julia = "1.5"
|
335 |
"""
|
336 |
|
|
|
1031 |
else:
|
1032 |
Pkg.instantiate()
|
1033 |
except RuntimeError as e:
|
1034 |
+
raise ImportError(import_error_string(self.julia_project)) from e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1035 |
Main.eval("using SymbolicRegression")
|
1036 |
|
1037 |
Main.plus = Main.eval("(+)")
|