最近,我一直在学习Visual Studio代码中的数据科学,当我尝试使用它时,我一直在使用的所有模块都不断给出ModuleNotFoundError。
我试过在Visual Studio代码终端和Mac内部的终端中安装它们。
^我使用了各种可能的配置,比如使用pip而不是pip 3,甚至试图下载sklearn,因为我认为这是一个单独的东西,我必须得到。
我还看了其他堆栈溢出问题。
最近我尝试使用scikit-learn模块,其中包括sklearn
下面是我的代码的导入部分:
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression #finds correlation between data and a trend line
from sklearn import metrics
import pandas as pd
import math
字符串
这是我得到的错误:"/Users/ethancha/Downloads/Data Science club/scikit.py" Traceback (most recent call last): File "/Users/ethancha/Downloads/Data Science club/scikit.py", line 7, in <module> from sklearn.model_selection import train_test_split ModuleNotFoundError: No module named 'sklearn'
从另一个堆栈溢出问题中,我尝试在代码的顶部添加以下内容:
import sys
sys.path.insert(0, r"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages")
sys.executable
型
这只是给了一个新的错误(我复制了文件路径的地方,它是根据论坛)。
错误代码:
Traceback (most recent call last):
File "/Users/ethancha/Downloads/Data Science club/scikit.py", line 7, in <module>
from sklearn.model_selection import train_test_split
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sklearn/__init__.py", line 79, in <module>
from . import (
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sklearn/__check_build/__init__.py", line 47, in <module>
raise_build_error(e)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sklearn/__check_build/__init__.py", line 31, in raise_build_error
raise ImportError("""%s
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sklearn/__check_build:
__init__.py __pycache__ _check_build.cpython-312-darwin.so
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
型
如何使用这些模块而不出现这些问题?
1条答案
按热度按时间bmp9r5qi1#
尝试使用python虚拟环境
你需要创建一个python虚拟环境并激活它
字符串
您有一个名为
venv
的文件夹。现在运行以下命令型
现在安装sklearn
型
你也可以在visual studio代码中选择虚拟环境。只需按
ctrl
+shift
+p
并搜索Select Interpreter
并选择本地环境,然后运行ipython
和jupyter-notebook
shell或运行python文件。