skip to Main Content

I’m using Ubuntu 20.04.5 LTS. Output of python3 --version command: Python 3.8.10
When I type pip in terminal and press TAB, it responds with the following options: pip, pip3, pip3.10 and pip3.8

But, when I use any of then with the --version flag, it all prints the same output, which is: pip 22.3.1 from /home/myuser/.local/lib/python3.8/site-packages/pip (python 3.8)

When I use "pip list" command, I can see the "virtualenv" package version(which is 20.17.0)

Then I create my virtual environment using this following command: python3 -m venv .env

Then I activate it using source .env/bin/activate command

Before installing the modules, I update virtual environment’s pip, using the following command:

.env/bin/python3 -m pip install --upgrade pip

Also, I have a file called requirements.txt with the packages names I need in it:

wheel
numpy
matplotlib
sklearn
seaborn

So I install them using the following command:

.env/bin/pip install -r requirements.txt --no-cache-dir --use-pep517

Finally, I try to run my python program using ".env/bin/python kmeans3.py" command, it prints this error:

Traceback (most recent call last):
  File "kmeans3.py", line 10, in <module>
    from sklearn.cluster import KMeans 
ModuleNotFoundError: No module named 'sklearn'

obs: This is the first 12 lines of the file:

"""
.env/bin/python3 -m pip install --upgrade pip
.env/bin/pip install -r requirements.txt --no-cache-dir --use-pep517
"""

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
import seaborn as sns
from sklearn.cluster import KMeans 
from sklearn.metrics import silhouette_score
from sklearn.preprocessing import MinMaxScaler

2

Answers


  1. Chosen as BEST ANSWER

    I don't know why is that, but I solved this problem installing "scikit-learn" package before install "sklearn"


  2. Looks ok to me.
    If your environment is activated try to just run

    python kmeans3.py
    

    or

    python3 kmeans3.py
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search