ImportError: No module named watson_developer_cloud

ImportError: No module named watson_developer_cloud

## Packages
import sys
import os
import glob
import json
import matplotlib.pyplot as plt
import watson_developer_cloud

## Cloud service credential connection
discovery_creds = helper.fetch_credentials('discovery')

discovery = watson_developer_cloud.DiscoveryV1(
                        version='2018-08-01',
                        url=discovery_creds['url'],
                        iam_apikey=discovery_creds['apikey'])

## Environment initialization
env, env_id = helper.fetch_object(
    discovery, "environment", "Compugin",
    create=True, create_args=dict(
        description="Compugin 1.0 -- Question/Answering"
    ))

# Lists existing configurations for the service instance and store default configuration id
configurations = discovery.list_configurations(environment_id=env_id).get_result()
cfg_id =  configurations['configurations'][0]['configuration_id']
print(json.dumps(configurations, indent=2))

# List default configuration details
config = discovery.get_configuration(environment_id=env_id, configuration_id=cfg_id).get_result()
print(json.dumps(config, indent=2))

# Test configuration on some sample text
data_dir = "data"
filename = os.path.join(data_dir, "sample.html")
with open(filename, "r") as f:
    res = discovery.test_configuration_in_environment(environment_id=env_id, configuration_id=cfg_id, file=f).get_result()
print(json.dumps(res, indent=2))

当尝试 运行 上述 python 代码时,我收到此错误:

回溯(最近调用最后): 文件 "compugin.py",第 7 行,位于 导入 watson_developer_cloud 导入错误:没有名为 watson_developer_cloud

的模块

我已经使用 pip 安装了 watson_developer_cloud 包,不确定我做错了什么。

当我们使用 pip 安装包时有两个世界 - 全局站点包和 virtualenv 包

Creating Virtual Environments Python “Virtual Environments” allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally.

Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python3.6/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtual environments can help you. They have their own installation directories and they don’t share libraries with other virtual environments.

Currently, there are two common tools for creating Python virtual environments:

venv is available by default in Python 3.3 and later, and installs pip and setuptools into created virtual environments in Python 3.4 and later. virtualenv needs to be installed separately, but supports Python 2.7+ and Python 3.3+, and pip, setuptools and wheel are always installed into created virtual environments by default (regardless of Python version).

阅读installing packages

全局站点包和virtualenv包的区别,参考pip installing in global site-packages instead of virtualenv

检查你是否还没有安装然后运行这个安装

pip install watson_developer_cloud