知道为什么我什至没有导入它时会收到 PIL 错误吗?



我正在尝试探索更多的学习路径,并在其他中使用matplotlab,然而无论我尝试什么,各种网站等似乎都不起作用。如果有人能解释为什么我得到一个PIL错误(是的,我确实读了错误,并做了所有提到的搜索),但没有任何改变,所以如果有人能解释给我,我将非常感激,已经尝试了几个小时了。

代码:

# Created by Simon Ranger : December 15th 2022
"""
A general expense tracker that is displayed in table format as well as statistical format
How to use:
1. when prompt enter the data you want to be stored
Desired Output:
The user can add to a variety of lists relating to what expenses they wanted, food, general, etc. which will be both
displayed in a file and the terminal.
"""
# Imports required
from pandas import DataFrame as df, read_csv, DataFrame
import numpy as np
from matplotlib import pyplot as plt
from datetime import date
# create empty lists
GoodsOrServices: list | str = []
Prices: list | float = []
Dates: list | date = []
ExpenseType: list | str = []

# funct adding data to lists
def addingData(goodsOrServices: str, prices: int | float, dates, expenseType: str) -> None:
# appending to the lists
GoodsOrServices.append(goodsOrServices)
Prices.append(prices)
Dates.append(dates)
ExpenseType.append(expenseType)

def reportData() -> DataFrame:
expenseType = ""
# creating the dataframe
report = df()
report["GoodsOfServices"] = GoodsOrServices
report["Prices"] = Prices
report["Dates"] = Dates
report["ExpenseType"] = ExpenseType
report.to_csv("Expenses.csv")
# creating an array to loop through the data and pull the data for each section
FoodP = []
HouseP = []
TravelP = []
# reads the file that was created above
with open("Expenses.csv"):
read_csv("Expenses.csv", skiprows=1)
for _ in enumerate(report):
if expenseType == "Food":
Prices.append(FoodP)
elif expenseType == "Household":
Prices.append(HouseP)
elif expenseType == "Travel":
Prices.append(TravelP)
elif _:
print(f"Error: Something went wrong!")
# putting the data into a graph
plt.plot(report)
plt.legend()
plt.show()
return report

def main():
# option menu for the user
truth: int = 1
user: str = (input(f"Please enter your name: "))
while truth != 0:
options = int(
input(f"Welcome {user} to this interactive expense tracker!nPlease select an option below:n1. Add "
f"Food Expensesn2. Household expensesn3. Travel Expensesn4. Display and Save the "
f"Expense Reportn0. ExitnPlease enter the choice here: "))
match options:
case 0:
exit(f"Thank you for using the Expense Tracker. See you next time!")
case 1:
print(f"Adding Foodn")
expenseType = "Food"
case 2:
print(f"Adding Householdn")
expenseType = "Household"
case 3:
print(f"Adding Traveln")
expenseType = "Travel"
case 4:
reportData()
# lets the user enter the data
if options == 1 or options == 2 or options == 3:
goodsOrservices = str(input(f"Enter the goods or services for the expense type {expenseType}:n")).strip()
price = float(input(f"Enter the price of the goods or service:n"))
today = date.today()
addingData(goodsOrservices, price, today, expenseType)

if __name__ == "__main__":
main()

错误:

Traceback (most recent call last):
File "C:UsersGeneralDesktopCodesPythonProgramsAdvancedExpenseTracker.py", line 17, in <module>
from matplotlib import pyplot as plt
File "C:UsersGeneralDesktopCodesPythonvenvLibsite-packagesmatplotlib__init__.py", line 113, in <module>
from . import _api, _version, cbook, _docstring, rcsetup
File "C:UsersGeneralDesktopCodesPythonvenvLibsite-packagesmatplotlibrcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "C:UsersGeneralDesktopCodesPythonvenvLibsite-packagesmatplotlibcolors.py", line 51, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'

pip安装最初已损坏或错误,擦除所有内容后重新安装

相关内容

最新更新