'Color package in python 3.10

I'm using python 3.10. I'm trying to use the package Color using this code:

from Color import Color

But I get the following error :

NoModuleNamed Color

Then I tried to install the package color, But I get this time the following error :

ERROR: Could not find a version that satisfies the requirement color (from versions: 0.1.1)
ERROR: No matching distribution found for color

If you have any idea about how I can solve this issue, please help

EDIT

Here is the whole code :

from gurobipy import *
import numpy as np
import matplotlib.pyplot as plt


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n =11
    clients = [i for i in range(n) if i !=0]
    nodos = [0] + clients
    arcos = [(i,j) for i in nodos for j in nodos if i!=j]

    #Demands
    np.random.seed(0)
    q={n:np.random.randint(10,15) for n in clients}
    q[0]=0

    #Ventas de tiempo
    e = {0:0 , 1:10 , 2:10 , 3:10 , 4:20 , 5:20 , 6:20 , 7:40 , 8 :40 , 9:40 , 10 : 40}
    l = {0:200 , 1:100 , 2:100 , 3:100 , 4:150 , 5:150 , 6:150 , 7:180 , 8 :180 , 9:180 , 10 : 180}

    s = {n:np.random.randint(3,5) for n in clients}
    s[0] = 0

    #Vehicles
    vehicles = [1,2,3,4]
    #Q=50
    Q = {1:50,2:50 , 3:25 , 4:25}

    #Coordinates
    X = np.random.rand(len(nodos))*100
    Y = np.random.rand(len(nodos))*100
    distances = {(i,j) : np.hypot(X[i] - X[j] , Y[i] - Y[j]) for i in nodos for j in nodos if i!=j}
    tiempo = {(i, j): np.hypot(X[i] - X[j], Y[i] - Y[j]) for i in nodos for j in nodos if i != j}


    plt.figure(figsize=(12,5))
    plt.scatter(X,Y,color='blue')


    plt.scatter(X[0],Y[0],color='red' , marker = 'D')
    plt.annotate("DC|$t_{%d}$=(%d$,%d$)" %(0,e[0],l[0]) , (X[0]-1,Y[0]-5.5))

    for i in clients:
        plt.annotate('$q_{%d}=%d$|$t_{%d}$=(%d$,%d$)' %(i,q[i],i,e[i],l[i]),(X[i]+1, Y[i]))

    plt.xlabel("Distance X")
    plt.ylabel("Distance Y")
    plt.title("Solution du problème")

    #plt.show()

    #Résolution du problème

    arco_var = [(i,j,k) for i in nodos for j in nodos for k in vehicles if i!=j]
    arcos_tiempos = [(i,k) for i in nodos for k in vehicles ]

    #Modelo :

    model = Model('VRPTW')


    #Variables de décision

    x=model.addVars(arco_var,vtype=GRB.BINARY,name='x')
    t=model.addVars(arcos_tiempos,vtype=GRB.CONTINUOUS,name = 't')

    #Fonction objectif
    model.setObjective(quicksum(distances[i,j]*x[i,j,k] for i,j,k in arco_var),GRB.MAXIMIZE)

    #Contraintes :

    model.addConstrs(quicksum(x[0,j,k] for j in clients) <= 1 for k in vehicles)
    model.addConstrs(quicksum(x[i, 0, k] for i in clients) <= 1 for k in vehicles)

    #- Un vehiculo por nodo :
    model.addConstrs(quicksum(x[i,j,k] for j in nodos for k in vehicles if i!=j) ==1 for i in clients)
     #- Conservacion de flujo :
    model.addConstrs(quicksum(x[i,j,k] for j in nodos if i!=j)-quicksum(x[j,i,k] for j in nodos if i!=j)==0 for i in nodos for k in vehicles)




     #- Capacidad del vehiculo :
    model.addConstrs(quicksum(q[i]*quicksum(x[i,j,k] for j in nodos if i != j) for i in clients) <= Q[k] for k in vehicles )

    #- Ventana de Tiempo :
    model.addConstrs((x[i,j,k] == 1) >> (t[i,k]+s[i]+tiempo[i,j] == t[j,k]) for i in clients for j in clients for k in vehicles if i != j )

    model.addConstrs(t[i,k] >= e[i] for i,k in arcos_tiempos)
    model.addConstrs(t[i, k] <= l[i] for i, k in arcos_tiempos)

    #model.Params.timeLimit = 60
    #model.Params.MipGap = 0.1

    model.optimize()

    print("Fonction objectif :" , str(round(model.ObjVal,2)))
    for v in model.getVars():
        if v.x > 0.9:
            print(str(v.VarName)+"="+str(v.x))
# See PyCharm help at https://www.jetbrains.com/help/pycharm/


    rutas=[]
    truck=[]
    k=vehicles
    N=nodos
    for k in vehicles:
        for i in nodos:
            if i != 0 and x[0,i,k].x > 0.9:
                aux = [0,i]
                while i != 0:
                    j = i
                    for h in nodos:
                        if j != h and x[j,h,k].x > 0.9:
                            aux.append(h)
                            i = h
                rutas.append(aux)
                truck.append(k)

    print(rutas)
    print(truck)

    tiempo_acum = list()
    for n in range(len(rutas)):
        for k in range(len(rutas[n])-1):
            if k ==0:
                aux=[0]
            else:
                i=rutas[n][k]
                j=rutas[n][k+1]
                t=tiempo[i,j]+s[i]+aux[-1]
                aux.append(t)
        tiempo_acum.append(aux)

    from colour import Color
    import matplotlib.patches as mpatches

    plt.figure(figsize=(12,5))
    plt.scatter(X,Y,color='blue')

    #DC
    plt.scatter(X[0],Y[0],color='red',marker='D')
    plt.annotate("DC",(X[0]-1,Y[0]-5.5))


    # Imprimiendo las rutas:
    for r in range(len(rutas)):
        for n in range(len(rutas[r])-1):
            i=rutas[r][n]
            j=rutas[r][n+1]
            print(r)
            plt.plot([X[i],X[j],Y[i],Y[j]],color=Color(0),alpha = 0.4)

    for r in range(len(tiempo_acum)):
        for n in range(len(tiempo_acum[r])):
            i = rutas[r][n]
            plt.annotate('$q_{%d}=%d$ |$t_{%d}=%d$' %(i,q[i],i,tiempo_acum[r][n]),(X[i]+1,Y[i]))
    patch = [mpatches.Patch(color=Color(n),label="vehicles"+str(truck[n])+"|cap="+str(Q[truck[n]])) for n in range(len(truck))]
    plt.legend(handles=patch,loc='best')
    plt.xlabel("Distancia X")
    plt.ylabel("Distancia Y")
    plt.title("Vehicle Routing Problem")

    plt.show()

I'm using those code , I got it from a tuto on Youtube



Solution 1:[1]

If you're really set on using Color rather than Colour or another module (I'm not sure I'd use Color - it has no description on pypi and does not seem well supported at all) - you can download the tar ball from https://pypi.org/project/color/#files and then install it manually using

pip install relative_path_to_color-0.1.1.tar.gz

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1