简体   繁体   中英

error when importing google-cloud-bigquery python module

so i replaced the google-cloud package installation with the google-cloud-bigquery one as google-cloud has been depreacated :

Requirement already up-to-date: google-cloud-bigquery in /usr/local/lib/python3.5/dist-packages (1.5.0)

Now the issue is that when I try to import the package I get a syntax error which really I do not understand:

    import google-cloud-bigquery as bq
             ^SyntaxError: invalid syntax

This is doing my head in, can someone please help, what is the problem with importing this package?

采用:

from google.cloud import bigquery

The reason for the syntax error is that the minus sign is an illegal character in a package or module name. Typically packages will use underscores in the actual package names, or have a nested structure, as in this case: import google.cloud.bigquery as bq

The google-cloud-bigquery syntax has to be implemented during the Client Library installation phase; however, the correct way to import the Google Cloud client library is by using the from google.cloud import bigquery format. You can use the following Google's official example as a reference:

# Imports the Google Cloud client library
from google.cloud import bigquery

# Instantiates a client
bigquery_client = bigquery.Client()

# The name for the new dataset
dataset_id = 'my_new_dataset'

# Prepares a reference to the new dataset
dataset_ref = bigquery_client.dataset(dataset_id)
dataset = bigquery.Dataset(dataset_ref)

# Creates the new dataset
dataset = bigquery_client.create_dataset(dataset)

print('Dataset {} created.'.format(dataset.dataset_id))

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