简体   繁体   English

来自google.cloud导入语言ModuleNotFoundError:没有名为“ google.cloud”的模块

[英]from google.cloud import language ModuleNotFoundError: No module named 'google.cloud'

I had a code that I was able to run last year using Google Cloud Natural Language. 我有一个去年可以使用Google Cloud Natural Language运行的代码。 I am not able to this year due to a library problem. 由于图书馆问题,今年我不能。 I used the following methods to install it. 我使用以下方法进行安装。 However, not successful. 但是,没有成功。 How should install it? 应该如何安装?

[jalal@goku sentiment]$  pip install --user  --upgrade google-cloud
Collecting google-cloud
  Downloading https://files.pythonhosted.org/packages/ba/b1/7c54d1950e7808df06642274e677dbcedba57f75307adf2e5ad8d39e5e0e/google_cloud-0.34.0-py2.py3-none-any.whl
Installing collected packages: google-cloud
Successfully installed google-cloud-0.34.0
[jalal@goku sentiment]$ python sentiment.py 
Traceback (most recent call last):
  File "sentiment.py", line 20, in <module>
    from google.cloud import language
ModuleNotFoundError: No module named 'google.cloud'
[jalal@goku sentiment]$ python -m pip install google-cloud
Requirement already satisfied: google-cloud in /home/grad3/jalal/.local/lib/python3.6/site-packages (0.34.0)

The error is: 错误是:

$ python sentiment.py 
Traceback (most recent call last):
  File "sentiment.py", line 20, in <module>
    from google.cloud import language
ModuleNotFoundError: No module named 'google.cloud'

A little about my system setup: 关于我的系统设置的一些信息:

$ which python
/scratch/sjn-p3/anaconda/anaconda3/bin/python
$ python
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 18:10:19) 
[GCC 7.2.0] on linux
$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.6.1810 (Core) 
Release:    7.6.1810
Codename:   Core

Also, I find it very weird when I am installing the pip package with Anacoda pip why does it install it into native Python and not Anaconda Python? 另外,当我用Anacoda pip安装pip包时,我觉得很奇怪,为什么将其安装到本机Python中而不是Anaconda Python中?

$ /scratch/sjn-p3/anaconda/anaconda3/bin/pip install --user  --upgrade google-cloud
Requirement already up-to-date: google-cloud in /home/grad3/jalal/.local/lib/python3.6/site-packages (0.34.0)

The issue is you are using the --user flag and pip but wish to run the Anaconda distribution of Python. 问题是您正在使用--user标志和pip但希望运行Python的Anaconda发行版。

If you do python -c 'import site; print(site.USER_BASE)' 如果您使用python -c 'import site; print(site.USER_BASE)' python -c 'import site; print(site.USER_BASE)' from the CLI it will return /home/grad3/jalal/.local hence why packages are installed there when you pass the --user flag to pip . 从CLI的python -c 'import site; print(site.USER_BASE)'将返回/home/grad3/jalal/.local因此,当您将--user标志传递给pip时,为什么要在其中安装软件包。 Since you want to use the Anaconda distribution you should stay consistent and use their version of a package manager, which would be conda in this case, which you can find about more --> here . 由于要使用Anaconda发行版,因此应保持一致并使用其软件包管理器的版本,在本例中为conda ,您可以在此处找到更多-> 这里

However, I highly recommend using virtual environments so that this issue can be avoided in the future. 但是,我强烈建议使用虚拟环境,以便将来可以避免此问题。 You can find out more about Anaconda virtual environments over --> here . 您可以在-> 此处找到有关Anaconda虚拟环境的更多信息。

If you wish to keep using pip along with Anaconda you can modify your target directory in the ~/.pip/pip.conf file to point at the location you want. 如果您希望与Anaconda一起继续使用pip ,则可以在~/.pip/pip.conf文件中修改target目录,以指向所需的位置。 Probably something along these lines will work: 这些路线可能会起作用:

[global]
target=/scratch/sjn-p3/anaconda/anaconda3/lib/python{version}/site-packages

Solved the problem by the following command. 通过以下命令解决了该问题。 You have to install the specific product from the Google Cloud (in this case Natural Language): 您必须从Google Cloud安装特定产品(在本例中为Natural Language):

$ pip install --user --upgrade google-cloud-language
Collecting google-cloud-language
  Using cached https://files.pythonhosted.org/packages/b1/3a/6f5808421aea97363cb19a095f73ed6eed12bbaee1e67f2145af7125585d/google_cloud_language-1.1.1-py2.py3-none-any.whl
Collecting google-api-core[grpc]<2.0.0dev,>=1.6.0 (from google-cloud-language)
  Using cached https://files.pythonhosted.org/packages/7d/73/e4877e921fe59307ec6b1b0b0c2ad9fde2d1c6bab8dd06ec913891a20dc6/google_api_core-1.8.2-py2.py3-none-any.whl
Requirement already satisfied, skipping upgrade: protobuf>=3.4.0 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (3.6.1)
Requirement already satisfied, skipping upgrade: pytz in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (2017.3)
Requirement already satisfied, skipping upgrade: six>=1.10.0 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (1.11.0)
Requirement already satisfied, skipping upgrade: requests<3.0.0dev,>=2.18.0 in /home/grad3/jalal/.local/lib/python3.6/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (2.21.0)
Collecting google-auth<2.0dev,>=0.4.0 (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language)
  Using cached https://files.pythonhosted.org/packages/c5/9b/ed0516cc1f7609fb0217e3057ff4f0f9f3e3ce79a369c6af4a6c5ca25664/google_auth-1.6.3-py2.py3-none-any.whl
Collecting googleapis-common-protos!=1.5.4,<2.0dev,>=1.5.3 (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language)
Requirement already satisfied, skipping upgrade: setuptools>=34.0.0 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (38.4.0)
Requirement already satisfied, skipping upgrade: grpcio>=1.8.2; extra == "grpc" in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (1.15.0)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from requests<3.0.0dev,>=2.18.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (2.6)
Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from requests<3.0.0dev,>=2.18.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (1.22)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from requests<3.0.0dev,>=2.18.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (2018.10.15)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages (from requests<3.0.0dev,>=2.18.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language) (3.0.4)
Collecting pyasn1-modules>=0.2.1 (from google-auth<2.0dev,>=0.4.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language)
  Using cached https://files.pythonhosted.org/packages/da/98/8ddd9fa4d84065926832bcf2255a2b69f1d03330aa4d1c49cc7317ac888e/pyasn1_modules-0.2.4-py2.py3-none-any.whl
Collecting cachetools>=2.0.0 (from google-auth<2.0dev,>=0.4.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language)
  Using cached https://files.pythonhosted.org/packages/39/2b/d87fc2369242bd743883232c463f28205902b8579cb68dcf5b11eee1652f/cachetools-3.1.0-py2.py3-none-any.whl
Collecting rsa>=3.1.4 (from google-auth<2.0dev,>=0.4.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language)
  Using cached https://files.pythonhosted.org/packages/02/e5/38518af393f7c214357079ce67a317307936896e961e35450b70fad2a9cf/rsa-4.0-py2.py3-none-any.whl
Collecting pyasn1<0.5.0,>=0.4.1 (from pyasn1-modules>=0.2.1->google-auth<2.0dev,>=0.4.0->google-api-core[grpc]<2.0.0dev,>=1.6.0->google-cloud-language)
  Using cached https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl
Installing collected packages: pyasn1, pyasn1-modules, cachetools, rsa, google-auth, googleapis-common-protos, google-api-core, google-cloud-language
  The scripts pyrsa-decrypt, pyrsa-encrypt, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/home/grad3/jalal/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed cachetools-3.1.0 google-api-core-1.8.2 google-auth-1.6.3 google-cloud-language-1.1.1 googleapis-common-protos-1.5.9 pyasn1-0.4.5 pyasn1-modules-0.2.4 rsa-4.0
$ vi ~/.bashrc

Added this line to the end of my ~/.bashrc (or whatever it is told to you): 将此行添加到我的〜/ .bashrc(或告诉您的任何内容)的末尾:

export PATH=/home/grad3/jalal/.local/bin:$PATH

$ source ~/.bashrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从google.cloud导入bigquery ModuleNotFoundError:没有名为“ google”的模块 - from google.cloud import bigquery ModuleNotFoundError: No module named 'google' 来自google.cloud导入firestore ModuleNotFoundError:没有名为&#39;google&#39;的模块 - from google.cloud import firestore ModuleNotFoundError: No module named 'google' ModuleNotFoundError:没有名为“google.cloud”的模块 - ModuleNotFoundError: No module named 'google.cloud' 没有名为 google.cloud 的模块 - No module named google.cloud from google.cloud import Speech_v1 ---- ModuleNotFoundError: No module named &#39;google&#39; - from google.cloud import speech_v1 ---- ModuleNotFoundError: No module named 'google' ModuleNotFoundError:没有名为“google.cloud”的模块,即使我安装了它 - ModuleNotFoundError: No module named 'google.cloud' even though I installed it 没有名为“google.cloud”的模块 Dockerfile python - No module named 'google.cloud' Dockerfile python 导入错误:ApacheBeam 上没有名为“google.cloud”的模块 - Import Error: No module named 'google.cloud' on ApacheBeam 无法从google.cloud导入存储空间 - Unable to import storage from google.cloud 如何从 google.cloud 导入 bigquery 模块 - how to import bigquery module from google.cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM