[英]Python modules I've just installed in my virtual env, are not found
I'm using Ubuntu 20.04.5 LTS.我正在使用 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 python3 --version
命令的 Output: Python 3.8.10当我在终端中键入pip
并按 TAB 键时,它会响应以下选项: pip 、 pip3 、 pip3.10和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)但是,当我将 then 中的任何一个与
--version
标志一起使用时,它都会打印相同的 output,即: pip 22.3.1 from /home/myuser/.local/lib/python3.8/site-packages/pip (蟒蛇 3.8)
When I use "pip list" command, I can see the "virtualenv" package version(which is 20.17.0)当我使用“pip list”命令时,我可以看到“virtualenv” package 版本(即 20.17.0)
Then I create my virtual environment using this following command: python3 -m venv.env
然后我使用以下命令创建我的虚拟环境:
python3 -m venv.env
Then I activate it using source.env/bin/activate
command然后我使用
source.env/bin/activate
命令激活它
Before installing the modules, I update virtual environment's pip, using the following command:在安装模块之前,我使用以下命令更新虚拟环境的 pip:
.env/bin/python3 -m pip install --upgrade pip
Also, I have a file called requirements.txt with the packages names I need in it:另外,我有一个名为requirements.txt的文件,其中包含我需要的包名称:
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:最后,我尝试使用“.env/bin/python kmeans3.py”命令运行我的 python 程序,它打印出以下错误:
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: obs:这是文件的前 12 行:
"""
.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
Looks ok to me.对我来说看起来不错。 If your environment is activated try to just run
如果您的环境已激活,请尝试运行
python kmeans3.py
or要么
python3 kmeans3.py
I don't know why is that, but I solved this problem installing "scikit-learn" package before install "sklearn"我不知道为什么会这样,但我在安装“sklearn”之前安装“scikit-learn” package 解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.