简体   繁体   English

Python 模块我刚刚安装在我的虚拟环境中,找不到

[英]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 键时,它会响应以下选项: pippip3pip3.10pip3.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.

相关问题 无法在虚拟环境中导入&#39;flask_wtf&#39;和&#39;wtforms&#39;,即使我已经安装了它们? - Unable to import 'flask_wtf' & 'wtforms' in a virtual env even though I've already pip installed them? Python 找不到已安装的模块 - Installed modules not found by Python Python从2.7.6更新到2.7.8-我只是失去了以前安装的所有模块吗? - Python update from 2.7.6 to 2.7.8 - did I just lose all my previously installed modules? 如何让python识别安装在虚拟环境中的模块? - how do I get python to recognize modules installed in virtual environment? 我刚刚开始使用 Python,但我的代码无法正常工作 - I've just started Python and my code isn't working 未找到安装了 pip 的 python 模块 - python modules installed with pip not found 在我的虚拟环境中找不到 pip 或 conda 命令 - No pip or conda command found in my virtual env (虚拟环境)(全局环境)为什么在激活它时会发生这种情况,而不仅仅是(虚拟环境)? - (virtual env)(global env) why is this happening instead of just (virtual env) when I activate it? 在我的虚拟环境中运行我的Python脚本? - Running my Python script in my virtual env? 我安装了 TensorFlow 发现没有找到模块 - I installed TensorFlow and found no modules found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM