Repository: MilesCranmer/PySR (language: python)

Issue:
Error Running PySR with Julia in Windows 10 (Anaconda Environment)
### Discussed in https://github.com/MilesCranmer/PySR/discussions/585

<div type='discussions-op-text'>

<sup>Originally posted by **sbalasbas3** March 27, 2024</sup>
**Environment Details:**

- Operating System: Windows-10-10.0.19045-SP0
- Python Version: 3.11.7
- Julia Version: (Unfortunately, I wasn't able to retrieve this detail due to the current issue, but it's supposed to be compatible with the latest pysr and juliacall versions.)
- juliacall Version: 0.9.19
- PySR Version: 0.18.0

**My Problem:**

Hello, I'm encountering an error when trying to use PySR. The initialization of PySR fails. Despite installing and setting up PySR and Julia, as well as ensuring that the juliacall package is up to date, I run into a CalledProcessError during the execution of Julia package management commands initiated by juliacall. I have no idea how to resolve this issue. This error occurs despite following the setup procedures for PySR and Julia within an Anaconda environment on Windows 10.

`CalledProcessError: Command '['C:\\Users\\[USERNAME]\\AppData\\Local\\anaconda3\\envs\\sym_reg\\julia_env\\pyjuliapkg\\install\\bin\\julia.exe', '--project=C:\\Users\\[USERNAME]\\AppData\\Local\\anaconda3\\envs\\sym_reg\\julia_env', '--startup-file=no', '-e', 'import Pkg; Pkg.Registry.update(); Pkg.add([Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d"), Pkg.PackageSpec(name="SymbolicRegression", uuid="8254be44-1295-4e6a-a16d-46603ac705cb", url=raw"https://github.com/MilesCranmer/SymbolicRegression.jl", rev=raw"v0.24.1"), Pkg.PackageSpec(name="Serialization", uuid="9e88b42a-f829-5b0c-bbe9-9e923198166b")]); Pkg.resolve(); Pkg.precompile()']' returned non-zero exit status 1.`

**Steps taken so far:**

- Ensured juliacall is up to date by running `pip install --upgrade juliacall`, which confirmed version 0.9.19 is installed.
- Attempted to manually specify the Julia executable's path using the JULIA_PYTHONCALL_EXE environment variable before importing PySR, without success. I wrote the code like this: `julia_path = "C:\\Users\\[USERNAME]\\AppData\\Local\\anaconda3\\envs\\sym_reg\\julia_env\\pyjuliapkg\\install\\bin\\julia.exe"` and `os.environ["JULIA_PYTHONCALL_EXE"] = julia_path`
- Activated Julia Environment: I activated the specific Julia project environment located at `C:\Users\[USERNAME]\AppData\Local\anaconda3\envs\sym_reg\julia_env` using the `Pkg.activate` command, ensuring that all package operations were localized to this environment. After activating the environment, I executed `Pkg.instantiate()` to install and update dependencies as defined in the environment's Project.toml and Manifest.toml files. This command updated the registry and added the PythonCall v0.9.19 and SymbolicRegression v0.24.1 packages among others. I also used `Pkg.add()` to explicitly add `PythonCall`, `SymbolicRegression` and `Serialization`.</div>


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/update_backend_version.py b/.github/workflows/update_backend_version.py
index 5a000201..696da9f5 100644
--- a/.github/workflows/update_backend_version.py
+++ b/.github/workflows/update_backend_version.py
@@ -20,7 +20,7 @@
 major, minor, patch, *dev = pyproject_data["project"]["version"].split(".")
 pyproject_data["project"]["version"] = f"{major}.{minor}.{int(patch)+1}"
 
-juliapkg_data["packages"]["SymbolicRegression"]["rev"] = f"v{new_backend_version}"
+juliapkg_data["packages"]["SymbolicRegression"]["version"] = f"={new_backend_version}"
 
 with open(pyproject_toml, "w") as toml_file:
     toml_file.write(tomlkit.dumps(pyproject_data))
diff --git a/pyproject.toml b/pyproject.toml
index 9577862a..1ba9d492 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
 
 [project]
 name = "pysr"
-version = "0.18.0"
+version = "0.18.1"
 authors = [
     {name = "Miles Cranmer", email = "miles.cranmer@gmail.com"},
 ]
diff --git a/pysr/juliapkg.json b/pysr/juliapkg.json
index 60ded254..ee8d2c02 100644
--- a/pysr/juliapkg.json
+++ b/pysr/juliapkg.json
@@ -3,8 +3,7 @@
     "packages": {
         "SymbolicRegression": {
             "uuid": "8254be44-1295-4e6a-a16d-46603ac705cb",
-            "url": "https://github.com/MilesCranmer/SymbolicRegression.jl",
-            "rev": "v0.24.1"
+            "version": "=0.24.1"
         },
         "Serialization": {
             "uuid": "9e88b42a-f829-5b0c-bbe9-9e923198166b",


Test patch:
diff --git a/pysr/test/test_dev_pysr.dockerfile b/pysr/test/test_dev_pysr.dockerfile
index 3470a7fa..2978e82b 100644
--- a/pysr/test/test_dev_pysr.dockerfile
+++ b/pysr/test/test_dev_pysr.dockerfile
@@ -35,10 +35,10 @@ RUN mkdir /pysr/pysr/test
 
 # Now, we create a custom version of SymbolicRegression.jl
 # First, we get the version from juliapkg.json:
-RUN python3 -c 'import json; print(json.load(open("/pysr/pysr/juliapkg.json", "r"))["packages"]["SymbolicRegression"]["rev"])' > /pysr/sr_version
+RUN python3 -c 'import json; print(json.load(open("/pysr/pysr/juliapkg.json", "r"))["packages"]["SymbolicRegression"]["version"])' > /pysr/sr_version
 
-# Remove v from the version:
-RUN cat /pysr/sr_version | sed 's/^v//g' > /pysr/sr_version_processed
+# Remove any = or ^ or ~ from the version:
+RUN cat /pysr/sr_version | sed 's/[\^=~]//g' > /pysr/sr_version_processed
 
 # Now, we check out the version of SymbolicRegression.jl that PySR is using:
 RUN git clone -b "v$(cat /pysr/sr_version_processed)" --single-branch https://github.com/MilesCranmer/SymbolicRegression.jl /srjl