解决办法:
pip install --target=包路径 包名
示例
pip install --target=D:\ProgramData\Anaconda3\Lib\site-packages numpy
升级某些包时,用 pip install --upgrade ***命令更新,但出现无法卸载的情况:
ERROR: Cannot uninstall 'TBB'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
手动也无法删除
解决办法
找到要更新的python包存放地址:X:\ProgramData\Anaconda3\Lib\site-packages`,然后删除所有与这个包相关的文件和文件夹,再次更新即可成功。
报错:pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pip 的依赖项解析器当前未考虑安装的所有包。此行为是以下依赖项冲突的根源。
解决办法
重新安装更新ERROR
下面提示的包到指定版本即可解决
你可以先在终端中输入“python”,如果打开了应用商店,就说明环境变量有问题,这时要找到python的安装路径,如“C:\Python27\python.exe”,找到完整的路径后,再切换到setup.py所在目录,输入“python路径 setup.py install”。
原始回答链接:https://ask.csdn.net/questions/1053206
补充:如果使用anaconda,可以直接打开Anaconda Powershell Prompt
,然后cd到setup.py
目录下,再次使用python setup.py install
安装即可。
使用python setup.py install
时出现报错,看网上还有使用pip安装出现这样报错的。
解决办法
1、尝试先安装所需的依赖环境库,然后通过https://www.lfd.uci.edu/~gohlke/pythonlibs/
下载再次安装,如果 whl
没有,继续使用python setup.py install
安装。如果不行见第二种方法。
2、通过https://visualstudio.microsoft.com/visual-cpp-build-tools/
下载vs_BuildTools.exe
,选择C++桌面开发
,右侧选择如图,其中MSVC最好勾选提示版本(我上面提示的是C++ 14.0),然后点击下载安装。安装完成后再次使用python setup.py install
安装。(不要问为什么,我也不知道,只是这样做成功了)
解决办法
先安装所需环境的依赖库,再次安装Python包即可。
一是检查路径,同一个包中子文件夹的不需要文件夹名称,不同文件夹的需要【文件夹名称.包名】
二是检查包名是否与保留字符、一些函数名或者变量名重复?重复出现会导致这种情况;
三是环状导入(循环引用),A导入了B,B也导入了A。示例
一是包内容缺失,重新安装。
二是导入的包名和脚本名、变量名等重名,修改自己文件名称即可。
这个问题很复杂。需要全面检查项目中的文件。
一是排查检查项目工程目录,对应写的setup.py,查看packages、package_dir、package_data
,这里可以使用find_packages
函数来检查。package_dir={"a": "b"}
我也没搞懂,这些可以详细参考官方教程。
二是检查setup.py中是否有语法问题,classifiers
是否有问题,官方classifiershttps://pypi.org/classifiers/
三是排查检查工程文件,你的每一个脚本是否存在7.1、7.2中的问题。
类型1:
./common/maskApi.c(8): fatal error C1083: 无法打开包括文件: “math.h”: No such file or di
rectory
C:\Users\Administrator\AppData\Local\Temp\pip-build-env-ui37wv3g\overlay\Lib\site-packag
es\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set,
using 2 for now (Py2). This will change in a later release! File: C:\Users\Administrator\A
ppData\Local\Temp\pip-install-k97x7lqd\pycocotools_5fefa6c8ae604cdb8a94dcecd5860a3d\pycoco
tools\_mask.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
error: command 'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\
MSVC\\14.34.31933\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
error: subprocess-exited-with-error
× Building wheel for pycocotools (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
full command: 'C:\Users\Administrator\.conda\envs\mmlab\python.exe' 'C:\Users\Administra
tor\.conda\envs\mmlab\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' buil
d_wheel 'C:\Users\ADMINI~1\AppData\Local\Temp\tmpe6pz6bez'
cwd: C:\Users\Administrator\AppData\Local\Temp\pip-install-k97x7lqd\pycocotools_5fefa6c8
ae604cdb8a94dcecd5860a3d
Building wheel for pycocotools (pyproject.toml) ... error
ERROR: Failed building wheel for pycocotools
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml
-based projects
类型2:
Building wheel for pycocotools (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pycocotools (pyproject.toml) did not run successfully.
│ exit code: 1
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-38
creating build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-cpython-38\pycocotools
running build_ext
cythoning pycocotools/_mask.pyx to pycocotools\_mask.c
building 'pycocotools._mask' extension
creating build\temp.win-amd64-cpython-38
creating build\temp.win-amd64-cpython-38\Release
creating build\temp.win-amd64-cpython-38\Release\common
in\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\Administrator\AppDat
n -IC:\Users\Administrator\.conda\envs\mmlab\include -IC:\Users\Administrator\.conda\envs\
mmlab\Include "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.
34.31933\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC
\14.34.31933\ATLMFC\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC
\Auxiliary\VS\include" /Tc./common/maskApi.c /Fobuild\temp.win-amd64-cpython-38\Release\./
common/maskApi.obj
maskApi.c
./common/maskApi.c(8): fatal error C1083: 无法打开包括文件: “math.h”: No such file o
r directory
C:\Users\Administrator\AppData\Local\Temp\pip-build-env-lu2hq_w0\overlay\Lib\site-pa
ckages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not s
et, using 2 for now (Py2). This will change in a later release! File: C:\Users\Administrat
or\AppData\Local\Temp\pip-install-pqejrlig\pycocotools_ee168b37b0a54dc8b5dc1f8c6fa9cdcf\py
cocotools\_mask.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
error: command 'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Too
ls\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pycocotools
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml
-based projects
类型3:
Building wheel for pycocotools (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [25 lines of output]
D:\ProgramData\Anaconda3\envs\SAM\lib\site-packages\setuptools\installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
warnings.warn(
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-38
creating build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-cpython-38\pycocotools
running build_ext
cythoning pycocotools/_mask.pyx to pycocotools\_mask.c
c:\users\administrator\appdata\local\temp\pip-install-xu9m0v5o\pycocotools_ebd8446859f146b7a43e6969b6449559\.eggs\cython-0.29.34-py3.8.egg\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\Administrator\AppData\Local\Temp\pip-install-xu9m0v5o\pycocotools_ebd8446859f146b7a43e6969b6449559\pycocotools\_mask.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'pycocotools._mask' extension
creating build\temp.win-amd64-cpython-38
creating build\temp.win-amd64-cpython-38\Release
creating build\temp.win-amd64-cpython-38\Release\common
creating build\temp.win-amd64-cpython-38\Release\pycocotools
"D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -ID:\ProgramData\Anaconda3\envs\SAM\lib\site-packages\numpy\core\include -I./common -ID:\ProgramData\Anaconda3\envs\SAM\include -ID:\ProgramData\Anaconda3\envs\SAM\Include "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" /Tc./common/maskApi.c /Fobuild\temp.win-amd64-cpython-38\Release\./common/maskApi.obj
maskApi.c
./common/maskApi.c(8): fatal error C1083: 无法打开包括文件: “math.h”: No such file or directory
error: command 'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pycocotools
Running setup.py clean for pycocotools
Failed to build pycocotools
Installing collected packages: zipp, six, pyparsing, packaging, kiwisolver, fonttools, cython, cycler, contourpy, python-dateutil, importlib-resources, matplotlib, pycocotools
Running setup.py install for pycocotools ... error
error: subprocess-exited-with-error
× Running setup.py install for pycocotools did not run successfully.
│ exit code: 1
╰─> [23 lines of output]
running install
D:\ProgramData\Anaconda3\envs\SAM\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-38
creating build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-cpython-38\pycocotools
running build_ext
skipping 'pycocotools\_mask.c' Cython extension (up-to-date)
building 'pycocotools._mask' extension
creating build\temp.win-amd64-cpython-38
creating build\temp.win-amd64-cpython-38\Release
creating build\temp.win-amd64-cpython-38\Release\common
creating build\temp.win-amd64-cpython-38\Release\pycocotools
"D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -ID:\ProgramData\Anaconda3\envs\SAM\lib\site-packages\numpy\core\include -I./common -ID:\ProgramData\Anaconda3\envs\SAM\include -ID:\ProgramData\Anaconda3\envs\SAM\Include "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" /Tc./common/maskApi.c /Fobuild\temp.win-amd64-cpython-38\Release\./common/maskApi.obj
maskApi.c
./common/maskApi.c(8): fatal error C1083: 无法打开包括文件: “math.h”: No such file or directory
error: command 'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> pycocotools
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
问题描述
使用pip安装和源码编译都不行,报错显示pycocotools这个包无法build,并且应该不是pip的问题。
原因分析
如果报错是error: Microsoft Visual C++ 14.0 is required.
,那和MVC是有一定关系的,最好安装MVC完再尝试是否报错。我这里显示和MVC无关,主要是pycocotools的问题,网上查到pycocotools的windows版本已经停止维护了,因此需要找一个合适的pycocotools版本包。
解决办法
1、 使用pip install pycocotools==2.0.2
解决问题。
2、pip install pycocotools-windows -i https://pypi.tuna.tsinghua.edu.cn/simple
3、使用conda install -c conda-forge pycocotools
安装,如果使用的是conda环境,强烈建议使用该方法!!!!
注:我是因为其它问题导致的,使用pycocotools-windows
安装完后没有解决问题,所以在某些包中pycocotools-windows
是不能替代pycocotools
的。
安装完成后可以测试一下,在命令行输入:python -c 'import pycocotools._mask as mask'
如果没有报错,说明可以导入。