duckylucky
duckylucky

Reputation: 1

ModuleNotFoundError: No module named 'urllib3.packages.six.moves' in a simple weather app

When I run the code, I get the error "ModuleNotFoundError: No module named 'urllib3.packages.six.moves", this is despite the fact that I have uninstalled and reinstalled six, requests and urllib3 many times.

Code:

import requests
import json


def get_weather(city, api_key):
    base_url = "http://api.openweathermap.org/data/2.5/weather?"


    complete_url = base_url + "q=" + city + "&appid=" + api_key + "&units=metric"

    response = requests.get(complete_url)
    data = response.json()

    if data["cod"] != "404":
        main = data["main"]
        wind = data["wind"]
        weather = data["weather"][0]
        temperature = main["temp"]
        humidity = main["humidity"]
        weather_description = weather["description"]
        wind_speed = wind["speed"]

        print(f"City: {city}")
        print(f"Temperature: {temperature}°C")
        print(f"Humidity: {humidity}%")
        print(f"Weather: {weather_description.capitalize()}")
        print(f"Wind Speed: {wind_speed} m/s")

    else:
        print(f"City {city} not found. Please enter a valid city name.")


if __name__ == "__main__":
    api_key = "5a249ac961fe0222f884ded14818c13e"
    city = input("Enter city name: ")
    get_weather(city, api_key)

I tried to run the program, a text output was meant to appear which then asked for the users city for them to then input it and weather info to appear. I have tried reinstalling six, requests and urllib3, deleted a 0kb version of python in the microsoft directory and done "sfc /scannow".

Upvotes: 0

Views: 645

Answers (1)

Charles Knell
Charles Knell

Reputation: 583

Your code also works fine in Windows. Are you using a virtual environment? If not, try "pip list" at a command prompt to verify that urllib3 is in the list. If you are using a virtual environment, activate it and do a "pip list" at a command prompt and check the list for urllib3. It's possible that the environment (virtual or system) you are using when you run the code still doesn't have urllib3 installed.

Upvotes: 0

Related Questions