Repository: mlflow/mlflow

Issue:
[BUG] mlflow run windows path issue
### Issues Policy acknowledgement

- [X] I have read and agree to submit bug reports in accordance with the [issues policy](https://www.github.com/mlflow/mlflow/blob/master/ISSUE_POLICY.md)

### Willingness to contribute

Yes. I can contribute a fix for this bug independently.

### MLflow version

- Client: 2.4.1


### System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Windows 10
- **Python version**: 3.11.3
- **yarn version, if running the dev UI**:


### Describe the problem

When running the example code from https://github.com/mlflow/mlflow/tree/master/examples/sklearn_elasticnet_wine it fails when using the virtualenv when running on Windows.

I located the error to stem from the missing cast to str when running on Windows here:
https://github.com/mlflow/mlflow/blob/master/mlflow/utils/virtualenv.py#L235

### Tracking information

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```shell
REPLACE_ME
```


### Code to reproduce issue

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
mlflow run sklearn_elasticnet_wine
```


### Stack trace

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```python
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Scripts\mlflow.exe\__main__.py", line 7, in <module>
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\mlflow\cli.py", line 204, in run
    projects.run(
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\mlflow\projects\__init__.py", line 338, in run
    submitted_run_obj = _run(
                        ^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\mlflow\projects\__init__.py", line 105, in _run
    submitted_run = backend.run(
                    ^^^^^^^^^^^^
  File "C:\Users\mhap\AppData\Local\pypoetry\Cache\virtualenvs\mlflow-test-h7ZMVinM-py3.11\Lib\site-packages\mlflow\projects\backend\local.py", line 182, in run
    command_str = command_separator.join(command_args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, WindowsPath found
```


### Other info / logs

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
REPLACE_ME
```


### What component(s) does this bug affect?

- [ ] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [ ] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [ ] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/recipes`: Recipes, Recipe APIs, Recipe configs, Recipe Templates
- [X] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [ ] `area/server-infra`: MLflow Tracking server backend
- [ ] `area/tracking`: Tracking Service, tracking client APIs, autologging

### What interface(s) does this bug affect?

- [ ] `area/uiux`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [ ] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [X] `area/windows`: Windows support

### What language(s) does this bug affect?

- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

### What integration(s) does this bug affect?

- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations


Discussion:
Great catch! Thank you for the investigation :) We'll gladly merge the PR once you file it. Let us know if you have any questions!

Resolving patch:
diff --git a/mlflow/utils/virtualenv.py b/mlflow/utils/virtualenv.py
--- a/mlflow/utils/virtualenv.py
+++ b/mlflow/utils/virtualenv.py
@@ -232,7 +232,7 @@ def _create_virtualenv(
     # Created a command to activate the environment
     paths = ("bin", "activate") if _IS_UNIX else ("Scripts", "activate.bat")
     activate_cmd = env_dir.joinpath(*paths)
-    activate_cmd = f"source {activate_cmd}" if _IS_UNIX else activate_cmd
+    activate_cmd = f"source {activate_cmd}" if _IS_UNIX else str(activate_cmd)
 
     if env_dir.exists():
         _logger.info("Environment %s already exists", env_dir)


Test patch: