试着去运行别人的代码
显示错误信息:
from sklearn.model_selection import train_test_split
ModuleNotFoundError: No module named 'sklearn'
按照以往的经验,这个包没有导入,只需要把这个包导入到环境中即可解决,于是我pip了一下
pip install sklearn
但是,很遗憾,显示了一堆错误“failed……”
Collecting sklearn
Downloading sklearn-0.0.post12.tar.gz (2.6 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [15 lines of output]
The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
rather than 'sklearn' for pip commands.
Here is how to fix this error in the main use cases:
- use 'pip install scikit-learn' rather than 'pip install sklearn'
- replace 'sklearn' by 'scikit-learn' in your pip requirements files
(requirements.txt, setup.py, setup.cfg, Pipfile, etc ...)
- if the 'sklearn' package is used by one of your dependencies,
it would be great if you take some time to track which package uses
'sklearn' instead of 'scikit-learn' and report it to their issue tracker
- as a last resort, set the environment variable
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True to avoid this error
More information is available at
https://github.com/scikit-learn/sklearn-pypi-package
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
于是我搜了“This error originates from a subprocess, and is likely not a problem with pip.
”
出现了下面的推文
https://blog.csdn.net/yuan2019035055/article/details/128709636
按照解决方法1尝试
PS D:../Scheduling-main> pip install nes-py --no-cache-dir
Collecting nes-py
Downloading nes_py-8.2.1.tar.gz (77 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.7/77.7 kB 539.4 kB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Collecting gym>=0.17.2 (from nes-py)
Downloading gym-0.26.2.tar.gz (721 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 721.7/721.7 kB 3.2 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.18.5 in d:\anaconda\envs\drl\lib\site-packages (from nes-py) (1.26.2)
Collecting pyglet<=1.5.21,>=1.4.0 (from nes-py)
Downloading pyglet-1.5.21-py3-none-any.whl (1.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 7.9 MB/s eta 0:00:00
Collecting tqdm>=4.48.2 (from nes-py)
Downloading tqdm-4.66.1-py3-none-any.whl.metadata (57 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.6/57.6 kB ? eta 0:00:00
Requirement already satisfied: cloudpickle>=1.2.0 in d:\anaconda\envs\drl\lib\site-packages (from gym>=0.17.2->nes-py) (1.2.2)
Requirement already satisfied: gym-notices>=0.0.4 in d:\anaconda\envs\drl\lib\site-packages (from gym>=0.17.2->nes-py) (0.0.8)
Collecting colorama (from tqdm>=4.48.2->nes-py)
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Downloading tqdm-4.66.1-py3-none-any.whl (78 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 kB ? eta 0:00:00
Building wheels for collected packages: nes-py, gym
Building wheel for nes-py (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-310
creating build\lib.win-amd64-cpython-310\nes_py
copying nes_py\nes_env.py -> build\lib.win-amd64-cpython-310\nes_py
copying nes_py\_image_viewer.py -> build\lib.win-amd64-cpython-310\nes_py
copying nes_py\_rom.py -> build\lib.win-amd64-cpython-310\nes_py
copying nes_py\__init__.py -> build\lib.win-amd64-cpython-310\nes_py
creating build\lib.win-amd64-cpython-310\nes_py\app
copying nes_py\app\cli.py -> build\lib.win-amd64-cpython-310\nes_py\app
copying nes_py\app\play_human.py -> build\lib.win-amd64-cpython-310\nes_py\app
copying nes_py\app\play_random.py -> build\lib.win-amd64-cpython-310\nes_py\app
copying nes_py\app\__init__.py -> build\lib.win-amd64-cpython-310\nes_py\app
creating build\lib.win-amd64-cpython-310\nes_py\wrappers
copying nes_py\wrappers\joypad_space.py -> build\lib.win-amd64-cpython-310\nes_py\wrappers
copying nes_py\wrappers\__init__.py -> build\lib.win-amd64-cpython-310\nes_py\wrappers
running build_ext
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for nes-py
Running setup.py clean for nes-py
Building wheel for gym (pyproject.toml) ... done
Created wheel for gym: filename=gym-0.26.2-py3-none-any.whl size=827635 sha256=93ce377d2648e4ec729f16da963ae3265c16e6d9090ec6ebeb5c1c35355df368
Stored in directory: C:\Users\RJH\AppData\Local\Temp\pip-ephem-wheel-cache-t7ebn6u4\wheels\b9\22\6d\3e7b32d98451b4cd9d12417052affbeeeea012955d437da1da
Successfully built gym
Failed to build nes-py
ERROR: Could not build wheels for nes-py, which is required to install pyproject.toml-based projects
又出现了failed……
于是我决定仔细阅读以下错误原因,终于发现,第一个错误里边人家已经很明确的提醒我了,是我输错了包的名字!
没有sklearns,我应该输入scikit-learn
于是我pip install scikit-learn
pip install scikit-learn
结果就成了!
PS D:../Scheduling-main> pip install scikit-learn
Collecting scikit-learn
Downloading scikit_learn-1.3.2-cp310-cp310-win_amd64.whl.metadata (11 kB)
Requirement already satisfied: numpy<2.0,>=1.17.3 in d:\anaconda\envs\drl\lib\site-packages (from scikit-learn) (1.26.2)
Requirement already satisfied: scipy>=1.5.0 in d:\anaconda\envs\drl\lib\site-packages (from scikit-learn) (1.11.4)
Collecting joblib>=1.1.1 (from scikit-learn)
Downloading joblib-1.3.2-py3-none-any.whl.metadata (5.4 kB)
Collecting threadpoolctl>=2.0.0 (from scikit-learn)
Downloading threadpoolctl-3.2.0-py3-none-any.whl.metadata (10.0 kB)
Downloading scikit_learn-1.3.2-cp310-cp310-win_amd64.whl (9.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.3/9.3 MB 925.9 kB/s eta 0:00:00
Downloading joblib-1.3.2-py3-none-any.whl (302 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 302.2/302.2 kB 4.6 MB/s eta 0:00:00
Downloading threadpoolctl-3.2.0-py3-none-any.whl (15 kB)
Installing collected packages: threadpoolctl, joblib, scikit-learn
Successfully installed joblib-1.3.2 scikit-learn-1.3.2 threadpoolctl-3.2.0
PS D:\DLMUR\DRLcode\wanghe-Crowdsourced-Courier-Scheduling-main> ^C
PS D:\DLMUR\DRLcode\wanghe-Crowdsourced-Courier-Scheduling-main>
就这样成了!
总结这个小坑,我应该还是在环境导入这块练手的少了,应该多折腾一下,才能有效避坑的!
最重要的一个是在出现错误的时候,我应该去读错误原因,而不是一味的去搜这个经验!毕竟跟自己出现同样错误的并不多。
以后不管是在什么问题中,都应该去直面问题,而不是直接去找别人的答案!
这种成了的感觉很奇妙,好好学习,希望能积少成多,直接是论文成了!