简体   繁体   English

vsc 无法识别 sklearn

[英]vsc won't recognize sklearn

I have scikit-learn installed and although it works fine in jupyter notebook, vsc keeps bringing up No module named 'sklearn' .我安装了 scikit-learn,尽管它在 jupyter notebook 中运行良好,但 vsc 不断显示No module named 'sklearn' I have uninstalled and reinstalled it and i have upgraded it, nothing works.我已经卸载并重新安装它并升级了它,但没有任何效果。

Installing collected packages: scikit-learn
Successfully installed scikit-learn-1.1.2
PS K:\portfolio_py> & "k:/portfolio_py/temporary app/virtual/Scripts/python.exe" k:/portfolio_py/titanic_random_forest.py
Traceback (most recent call last):
  File "k:\portfolio_py\titanic_random_forest.py", line 4, in <module>
    from sklearn.linear_model import LinearRegression, Ridge
ModuleNotFoundError: No module named 'sklearn'
PS K:\portfolio_py> pip install scikit-learn --upgrade
Requirement already satisfied: scikit-learn in c:\users\manos\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (1.1.2)
Requirement already satisfied: threadpoolctl>=2.0.0 in c:\users\manos\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn) (3.1.0)
Requirement already satisfied: joblib>=1.0.0 in c:\users\manos\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn) (1.1.0)
Requirement already satisfied: numpy>=1.17.3 in c:\users\manos\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn) (1.22.4)
Requirement already satisfied: scipy>=1.3.2 in c:\users\manos\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn) (1.9.0)


PS K:\portfolio_py> & "k:/portfolio_py/temporary app/virtual/Scripts/python.exe" k:/portfolio_py/titanic_random_forest.py
Traceback (most recent call last):
  File "k:\portfolio_py\titanic_random_forest.py", line 4, in <module>
    from sklearn.linear_model import LinearRegression, Ridge
ModuleNotFoundError: No module named 'sklearn'
PS K:\portfolio_py> 

This is where your sklearn package is installed这是安装sklearn package 的地方

Requirement already satisfied: scikit-learn in c:\users\manos\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (1.1.2)

This is your command to run the code这是您运行代码的命令

PS K:\portfolio_py> & "k:/portfolio_py/temporary app/virtual/Scripts/python.exe" k:/portfolio_py/titanic_random_forest.py

Obviously, your sklearn package is installed in the python310 environment.很明显,你的sklearn package是安装在python310环境下的。 And you use the python interpreter in the virtual environment to run the code.而你在虚拟环境中使用python解释器运行代码。

So the reason for the error is that the interpreter you are currently using is not the same interpreter that you installed the sklearn package with.所以错误的原因是您当前使用的解释器与您安装sklearn package 时使用的解释器不同。

There are two solutions here这里有两种解决方案

  • Switch the currently used interpreter切换当前使用的解释器
    1. Ctrl + Shift + P Ctrl + Shift + P
    2. Python: Select Interpreter Python: Select 翻译
    3. Select the python310 interpreter with the sklearn package installed Select 安装了sklearn package 的python310解释器
  • Install sklearn for the current virtual environment为当前虚拟环境安装sklearn
    1. Select the interpreter in the virtual environment Select 虚拟环境中的解释器
    2. Create a new terminal to activate the virtual environment新建终端激活虚拟环境
    3. Install sklearn in the terminal在终端中安装sklearn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM