Issue
I have scikit-learn installed and although it works fine in jupyter notebook, vsc keeps bringing up 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>
Solution
This is where your sklearn
package is installed
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. And you use the python interpreter in the virtual environment to run the code.
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.
There are two solutions here
- Switch the currently used interpreter
- Ctrl+Shift+P
- Python: Select Interpreter
- Select the python310 interpreter with the
sklearn
package installed
- Install
sklearn
for the current virtual environment- Select the interpreter in the virtual environment
- Create a new terminal to activate the virtual environment
- Install
sklearn
in the terminal
Answered By - JialeDu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.