Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI]: No module named 'pkg_resources' while import wandb #3440

Closed
YiranJing opened this issue Mar 30, 2022 · 6 comments
Closed

[CLI]: No module named 'pkg_resources' while import wandb #3440

YiranJing opened this issue Mar 30, 2022 · 6 comments
Labels
a:sdk Area: sdk related issues

Comments

@YiranJing
Copy link

YiranJing commented Mar 30, 2022

Describe the bug 🐛

without setuptools installation, I get error No module named 'pkg_resources' at line import wandb

Reason: pkg_resources belongs to setuptools, but wandb library missed setuptools dependency in requrienment.txt

To reproduce the error, run

pip uninstall setuptools
pip uninstall wandb
pip install wandb
python3 example.py

example.py:

import wandb
import uuid


from sklearn import datasets
from sklearn import ensemble
from sklearn import preprocessing
from sklearn import model_selection
from sklearn.metrics import f1_score

ENTITY = "entity"
PROJECT = "sweep-test"

def train():

    sweep_config = {
        "name": f"sweep-{str(uuid.uuid4())[:8]}",
        "method": "bayes",
        "metric": {"name": f"accuracy", "goal": "maximize"},
        "parameters": {
            "max_depth": {
                "distribution": "int_uniform",
                "min": 2,
                "max": 5,
            },
        },
    }

    sweep_id = wandb.sweep(sweep_config, project=PROJECT, entity=ENTITY)
    print("Sweep:", sweep_id)

    def _func() -> None:
        with wandb.init() as run:

            estimator_params = {k: v for k, v in wandb.config.items()}

            clf = ensemble.RandomForestClassifier(
                max_depth=wandb.config["max_depth"],
                n_estimators=3,
                criterion="gini",
                min_samples_split=5,
            )
            X, y = datasets.make_circles(noise=0.2, factor=0.5, random_state=0)
            X = preprocessing.StandardScaler().fit_transform(X)
            X_train, X_test, y_train, y_test = model_selection.train_test_split(
                X, y, test_size=0.4, random_state=0
            )
            clf.fit(X_train, y_train)
            
            accuracy = clf.score(X_test, y_test)
            print("Accuracy:", accuracy)

            y_pred = clf.predict(X_test)
            f1 = f1_score(y_test, y_pred, zero_division=1)
            print("f1:", f1)

            wandb.log({"accuracy": accuracy, "f1": f1})

    wandb.agent(sweep_id, function=_func, count=3)


   
if __name__ == "__main__":
    
    train()

full error message using example.py

Traceback (most recent call last):
  File "example.py", line 2, in <module>
    import wandb
  File "foo/python/.venv/lib/python3.9/site-packages/wandb/__init__.py", line 27, in <module>
    from wandb import sdk as wandb_sdk
  File "foo/python/.venv/lib/python3.9/site-packages/wandb/sdk/__init__.py", line 7, in <module>
    from .wandb_artifacts import Artifact  # noqa: F401
  File "foo/python/.venv/lib/python3.9/site-packages/wandb/sdk/wandb_artifacts.py", line 30, in <module>
    from wandb.apis import InternalApi, PublicApi
  File "foo/python/.venv/lib/python3.9/site-packages/wandb/apis/__init__.py", line 32, in <module>
    from .internal import Api as InternalApi  # noqa
  File "foo/python/.venv/lib/python3.9/site-packages/wandb/apis/internal.py", line 1, in <module>
    from wandb.sdk.internal.internal_api import Api as InternalApi
  File "foo/python/.venv/lib/python3.9/site-packages/wandb/sdk/internal/internal_api.py", line 12, in <module>
    from pkg_resources import parse_version  # type: ignore
ModuleNotFoundError: No module named 'pkg_resources'

Environment

WandB version: 0.12.11

Python version: 3.9.9

pip version: 21.3

OS

OSX and Linux

@YiranJing YiranJing added the a:sdk Area: sdk related issues label Mar 30, 2022
@thundergolfer
Copy link

Can confirm the reproduction instructions produce the same error trace for me. The setuptools package is a dependency of pip so it's almost always available in typical Python environments, but in more hermetic Python environments/deployments Weights & Biases' undeclared dependency on setuptools creates an import error.

@thundergolfer
Copy link

Related issue in another project: snowflakedb/snowflake-connector-python#546

@armanhar
Copy link

Thanks everyone for flagging. I'll file a ticket so our team can address this.

@exalate-issue-sync
Copy link

Arman Harutyunyan commented:
Hey everyone, this should be fixed now. Please let me know if you encounter the issue again.

@thundergolfer
Copy link

Thanks, looks like the fix landed here: #3516.

It will show up in the next release. cc @YiranJing

@thundergolfer
Copy link

thundergolfer commented May 11, 2022

Closeable as fixed by #3516

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:sdk Area: sdk related issues
Projects
None yet
Development

No branches or pull requests

3 participants