本文介绍了Google Cloud NL:ImportError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Google Cloud NL Api收到此错误消息.

I am getting this error message with Google Cloud NL Api.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-c22ac635f054> in <module>
      1 # Imports the Google Cloud client library
----> 2 from google.cloud import language
      3 from google.cloud.language import enums
      4 from google.cloud.language import types
      5

ImportError: cannot import name 'language' from 'google.cloud' (unknown location)

我尝试重新安装Google云语言.

I tried to re-install google cloud language.

此命令正在终端上运行(我得到了结果)

This command is working from the terminal (I get a result)

gcloud ml language analyze-entities --content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."

我认为我没有使用任何虚拟环境.

I don't think I'm using any virtual environment.

我想知道库是否安装在正确的位置,但是我不知道如何确定?

I'm wondering is the library is installed at the right location, but I don't know how to make sure?

推荐答案

实际上,它说您应该在虚拟环境中安装此库:

Actually it says here that you're supposed to install this library in a virtual environment:

https://pypi.org/project/google-cloud-language/

(注意:删除所有<> ;,并且不需要")

(note: remove all the < >, and no "" needed)

pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-language

然后,如果您使用的是Jupyter Notebook,则可以按照以下说明进行操作:

Then if you're using Jupyter Notebook you can just follow these instructions:

https://janakiev.com/blog/jupyter-virtual-envs/

最后,我从一个新的终端窗口重新启动了Jupyter.然后从菜单中选择内核/更改内核/您的环境的名称"而且有效!

At the end I restarted the Jupyter from a new terminal window.And from the menu I chose kernel / change kernel / "name of your environment"And it worked!

这篇关于Google Cloud NL:ImportError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:16