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.

[BUG] ModuleNotFoundError: No module named 'mlflow'

See original GitHub issue

Willingness to contribute

The MLflow Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the MLflow code base?

  • No. I cannot contribute a bug fix at this time.

System information

  • Have I written custom code (as opposed to using a stock example script provided in MLflow): I use the exact example sklearn_elasticnet_wine from MLFlow.
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • MLflow installed from (source or binary): pip
  • MLflow version (run mlflow --version): 1.20.2
  • Python version: 3.6.5
  • npm version, if running the dev UI: NA
  • Exact command to reproduce: mlflow run sklearn_elasticnet_wine

Describe the problem

  • Expected: To run successfully the example of sklearn_elasticnet_wine by running mlflow run sklearn_elasticnet_wine
  • Reality: Have ModuleNotFoundError: No module named 'mlflow' error.

Code to reproduce the issue

Provide a reproducible test case that is the bare minimum necessary to generate the problem.

  • Clone the MLFLow repo
  • cd examples
  • mlflow run sklearn_elasticnet_wine

Other info / logs

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

2021/10/01 16:37:19 INFO mlflow.projects.utils: === Created directory C:\Users\Admin\AppData\Local\Temp\tmpzyfvbj1q for downloading remote URIs passed to arguments of type 'path' ===
2021/10/01 16:37:19 INFO mlflow.projects.backend.local: === Running command 'conda activate mlflow-fef3fb3f401d7934c5d335df2b82655b31e59e85 && python train.py 0.5 0.1' in run with ID '5926bd275a8e4f3e98d6fa1077facc0c' ===
Traceback (most recent call last):
  File "train.py", line 15, in <module>
    import mlflow
ModuleNotFoundError: No module named 'mlflow'
2021/10/01 16:37:21 ERROR mlflow.cli: === Run (ID '5926bd275a8e4f3e98d6fa1077facc0c') failed ===

What component(s), interfaces, languages, and integrations does this bug affect?

Components

  • 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/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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jwyyycommented, Oct 3, 2021

Thanks for your detailed response and new infomation!

The issue is about activating multiple conda environments makes the second-activated environment uses Python from the base environment instead.

According to your answer, it seems that this does not happen on your side if the mlflow_test environment has Python in it, so my biggest guest is from the Conda behaviour on Windows OS, but yeah, still my guess, I haven’t paid more time researching on the root cause.

It is interesting to see this behavior. Based on your analysis, it seems it is a potential bug in conda on different OS. Will follow up on this issue more.

1reaction
tranctancommented, Oct 18, 2021

Hi, thank you for your dedicated response. Based on your response and some trials, somehow I found out the problem and fixed this, though I don’t understand why the issue occurs.

The issue is about activating multiple conda environments makes the second-activated environment uses Python from the base environment instead.

  • This is why when I activate a conda environment that is not base environment (in this case, test_mlflow environment) and run mlflow run, it yields an issue of Python is from the base environment.

Step to reproduce:

  • Create a conda environment, e.g test_mlflow with Python + MLFlow installed.
  • Activate test_mlflow & run mlflow run sklearn_elasticnet_wine
  • Then MLFlow Project creates new environment (mlflow_<serial_number>), runs the project and yields the error we talked about.

Reproduce again the error in more handy way:

(base) D:\WORK\mlflow\examples>conda activate test_mlflow

(test_mlflow) D:\WORK\mlflow\examples>conda activate mlflow-f1d746bcf57e2f4f48709a3067a87365cc1f75c2

(mlflow-f1d746bcf57e2f4f48709a3067a87365cc1f75c2) D:\WORK\mlflow\examples>python
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> import mlflow

See the warning up there?

According to your answer, it seems that this does not happen on your side if the mlflow_test environment has Python in it, so my biggest guest is from the Conda behaviour on Windows OS, but yeah, still my guess, I haven’t paid more time researching on the root cause.

Solution to make it works:

  • Install MLFlow in the base environment
  • Run mlflow run sklearn_elasticnet_wine from the base environment
  • Voila, everything works.
Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'mlflow' when running a notebook
From the error description, it looks like the mlflow library is not present. You can use ML cluster as these type of cluster...
Read more >
No module named 'mlflow.sklearn'; 'mlflow' is not a package ...
I am getting the below error. import mlflow.sklearn ModuleNotFoundError: No module named 'mlflow.sklearn'; 'mlflow' is not a package.
Read more >
mlflow: problems with pip installation - Stack Overflow
7/site-packages, I get "ModuleNotFoundError: No module named 'mlflow' error when I try to run code that imports mlflow module. How should I fix ......
Read more >
ModuleNotFoundError: No module named 'mlflow'
Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'mlflow' How to remove the ModuleNotFo.
Read more >
Quickstart — MLflow 2.0.1 documentation
By default mlflow run installs all dependencies using virtualenv. To run a project without using virtualenv , you can provide the --env-manager=local option...
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