简体   繁体   中英

iterative.ai MLEM | ModuleNotFoundError: No module named 'mlem.api'; 'mlem' is not a package

Goal: install and run Python script with MLEM code.

Following this installation guide in the library docs; pip install mlem should suffice.

Code:

from mlem.api import import_object

# ...

Traceback:

$ python3 app/deployment-poc/mlem.py
Traceback (most recent call last):
  File "/home/me/BitBucket/project/app/deployment-poc/mlem.py", line 1, in <module>
    from mlem.api import import_object
  File "/home/me/BitBucket/project/app/deployment-poc/mlem.py", line 1, in <module>
    from mlem.api import import_object
ModuleNotFoundError: No module named 'mlem.api'; 'mlem' is not a package

I've installed both via pip and conda .

$ which mlem
/home/me/miniconda3/envs/venv/bin/mlem
$ mlem --version
🐶 MLEM Version: 0.4.1
$ conda list
# packages in environment at /home/me/miniconda3/envs/venv:
#
# Name                    Version                   Build  Channel
fastapi                   0.89.1                   pypi_0    pypi
mlem                      0.4.1                    pypi_0    pypi
(venv) me@laptop:~/BitBucket/project$ pip install mlem --no-dependencies
Requirement already satisfied: mlem in /home/me/miniconda3/envs/venv/lib/python3.10/site-packages (0.4.1)
(venv) me@laptop:~/BitBucket/project$ pip show mlem
Name: mlem
Version: 0.4.1
Summary: Version and deploy your models following GitOps principles
Home-page: https://mlem.ai
Author: Mikhail Sveshnikov
Author-email: mike0sv@iterative.ai
License: Apache License 2.0
Location: /home/me/miniconda3/envs/venv/lib/python3.10/site-packages
Requires: aiohttp, aiohttp-swagger, cached-property, click, cloudpickle, dill, entrypoints, flatdict, fsspec, gitpython, importlib-metadata, isort, iterative-telemetry, Jinja2, pydantic, pyparsing, python-gitlab, python-multipart, requests, rich, typer
Required-by: 

Request to have a reputable member create new tag: mlem

You have a script /home/me/BitBucket/project/app/deployment-poc/mlem.py which shadows importable package mlem . With such a script import mlem in the script tries to import from the very script, not from the package.

Rename mlem.py to something different.

The bottom line: never name you scripts the same as importable packages. Never have email.py or test.py , etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM