Search code examples
pythonvisual-studio-codescheduled-taskspython-3.10prefect

I pip installed Prefect but it says "ModuleNotFoundError": 'No module named 'prefect'


I'm not sure what the issue is but

  • I already pip installed prefect and confirmed it's installed: Prefect 2.0
  • Using VsCode
  • Python 3.10.6

check image below for error and code posted for easy copy pasta

from prefect import flow, task
import httpx

@task(retries=3)
def get_stars(repo):
    url = f"https://api.github.com/repos/{repo}"
    count = httpx.get(url).json()["stargazers_count"]
    print(f"{repo} has {count} stars!")

@flow
def github_stars(repos):
    for repo in repos:
        get_stars(repo)

# call the flow!
github_stars(["PrefectHQ/Prefect", "PrefectHQ/prefect-aws",  "PrefectHQ/prefect-dbt"])

Prefect Install

Edit: Found the solution:

Solution found


Solution

  • I can see that you have not activated your virtualenv that might be the issue, you need to first install virtualenv.

    Using this you can install virtualenv in your system:

    pip install virtualenv
    

    then you have to create a virtual environment, you can do that by following command.

    python -m virtualenv myEnv # ---> whatever name you want here
    

    and then you have to activate the environment by following command:

    myEnv\Scripts\activate
    

    and to deactivate, simply use:

    deactivate