Hello, I have this flow which uploads data to GCS:...
# ask-community
i
Hello, I have this flow which uploads data to GCS:
Copy code
from pathlib import Path
from prefect import flow
from prefect_gcp import GcpCredentials, GcsBucket
import pandas as pd

@flow
def upload_to_gcs():
    name = 'ready_df.csv'
    file_path = Path(name)
    df = pd.read_csv(file_path)
    gcp_credentials = GcpCredentials.load("...", validate=False)
    gcs_bucket = GcsBucket(
        bucket="...",
        gcp_credentials=gcp_credentials
    )

    gcs_bucket.upload_from_dataframe(df=df, to_path=name)
    
    return None

if __name__ == "__main__":
    upload_to_gcs.serve(name="...")
To run this I install prefect-gcp, and with it the prefect version that comes is 2.19.7. My project is using 3.x. So if I upgrade to 3.x in the terminal where I just installed prefect-gcp, when running python this_flow.py I get:
Copy code
from prefect.infrastructure import Infrastructure, InfrastructureResult
ImportError: cannot import name 'Infrastructure' from 'prefect.infrastructure'
and I cannot .serve() it while having version 2.19.7 because I guess .serve was not available then and I get:
Copy code
prefect.deployments.runner.DeploymentApplyError: Error while applying deployment: Client error '422 Unprocessable Entity' for url '<http://127.0.0.1:4200/api/deployments/>'
Is this a known issue with prefect-gcp and prefect 3.x? Thank you
āœ… 1
a
If I understand correctly, I think you need to pip install the release candidate for prefect-gcp. I suspect what's happening is: •
pip install prefect-gcp
installs the last 2.x compatible version, since the 3.x compatible version is still a prerelease. • Then upgrading just the prefect dependency to 3.x, while keeping around a
prefect-gcp
version that is looking for some old import paths.
i
I am not sure I get how to do that ? I do
Copy code
pip install prefect-gcp
I get prefect 2.19.7, then I do
Copy code
pip install -U prefect --pre
and then when I run the flow, I get
Copy code
from prefect.infrastructure import Infrastructure, InfrastructureResult
ImportError: cannot import name 'Infrastructure' from 'prefect.infrastructure'
a
I think
pip install -U prefect-gcp --pre
might work here
i
works. Thank you very much ^^ (I am not aware of the effect of this --pre haha)
a
šŸ™Œ šŸ’ƒ šŸ”„