$ python -V
Python 3.12.5
python安装anndata2ri 一直报错,显示缺少distutils.msvc9compiler
(venv1) PS D:\pytest> pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple anndata2ri
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Collecting anndata2ri
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/a4/a2/ff2f5c1d714fddd9dc933129db0554ffd71103e3c26f8152a94041945f20/anndata2ri-1.3.2-py3-none-any.whl (27 kB)
Collecting anndata (from anndata2ri)
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/ca/a2/52b1fb4d7bbb022929300a4351c363958c1377b33c0d0be94f803987af7a/anndata-0.10.9-py3-none-any.whl (128 kB)
Collecting rpy2>=3.5.2 (from anndata2ri)
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/20/4a/2c7a3e08c4db3eb6c5fd050815b11947073997d0a521cd83c7dec1946d2e/rpy2-3.5.16.tar.gz (220 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [58 lines of output]
'sh' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
<string>:116: UserWarning: Command '('C:\\Program Files\\R\\R-4.4.1\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 1.
cffi mode is CFFI_MODE.ANY
R home found: C:\Program Files\R\R-4.4.1
R exec path: C:\Program Files\R\R-4.4.1\bin\x64\R
Looking for R CONFIG with: C:\Program Files\R\R-4.4.1\bin\x64\R CMD config --ldflags
'sh' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
rpy2/_rinterface_cffi_build.py:285: UserWarning: Command '('C:\\Program Files\\R\\R-4.4.1\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 1.
warnings.warn(str(e))
Traceback (most recent call last):
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\cffi\_shimmed_dist_utils.py", line 33, in <module>
from distutils.msvc9compiler import MSVCCompiler
ModuleNotFoundError: No module named 'distutils.msvc9compiler'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\pytest\venv1\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "D:\pytest\venv1\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\pytest\venv1\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\build_meta.py", line 332, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\build_meta.py", line 302, in _get_build_requires
self.run_setup()
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\build_meta.py", line 318, in run_setup
exec(code, locals())
File "<string>", line 206, in <module>
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\__init__.py", line 117, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 146, in setup
_setup_distribution = dist = klass(attrs)
^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\dist.py", line 283, in __init__
_Distribution.__init__(self, dist_attrs)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 278, in __init__
self.finalize_options()
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\dist.py", line 635, in finalize_options
ep(self)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\setuptools\dist.py", line 655, in _finalize_setup_keywords
ep.load()(self, ep.name, value)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\cffi\setuptools_ext.py", line 216, in cffi_modules
add_cffi_module(dist, cffi_module)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\cffi\setuptools_ext.py", line 69, in add_cffi_module
_add_py_module(dist, ffi, module_name)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\cffi\setuptools_ext.py", line 153, in _add_py_module
from cffi._shimmed_dist_utils import log, mkpath
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-n79suz4m\overlay\Lib\site-packages\cffi\_shimmed_dist_utils.py", line 36, in <module>
raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex
Exception: This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel 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.
ModuleNotFoundError: No module named 'distutils.msvc9compiler'
,看了文档,python 3.12版本中弃用了,推荐使用setuptools。
但是实际用起来并没有什么用,还是同样的错误:
(venv1) PS D:\pytest> pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple setuptools
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Collecting setuptools
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/df/b5/168cec9a10bf93b60b8f9af7f4e61d526e31e1aad8b9be0e30837746d700/setuptools-74.0.0-py3-none-any.whl (1.3 MB)
Installing collected packages: setuptools
Successfully installed setuptools-74.0.0
(venv1) PS D:\pytest> pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple anndata2ri
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Collecting anndata2ri
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/a4/a2/ff2f5c1d714fddd9dc933129db0554ffd71103e3c26f8152a94041945f20/anndata2ri-1.3.2-py3-none-any.whl (27 kB)
Collecting anndata (from anndata2ri)
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/ca/a2/52b1fb4d7bbb022929300a4351c363958c1377b33c0d0be94f803987af7a/anndata-0.10.9-py3-none-any.whl (128 kB)
Collecting rpy2>=3.5.2 (from anndata2ri)
Using cached https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/20/4a/2c7a3e08c4db3eb6c5fd050815b11947073997d0a521cd83c7dec1946d2e/rpy2-3.5.16.tar.gz (220 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [58 lines of output]
'sh' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
<string>:116: UserWarning: Command '('C:\\Program Files\\R\\R-4.4.1\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 1.
cffi mode is CFFI_MODE.ANY
R home found: C:\Program Files\R\R-4.4.1
R exec path: C:\Program Files\R\R-4.4.1\bin\x64\R
Looking for R CONFIG with: C:\Program Files\R\R-4.4.1\bin\x64\R CMD config --ldflags
'sh' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
rpy2/_rinterface_cffi_build.py:285: UserWarning: Command '('C:\\Program Files\\R\\R-4.4.1\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero exit status 1.
warnings.warn(str(e))
Traceback (most recent call last):
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\cffi\_shimmed_dist_utils.py", line 33, in <module>
from distutils.msvc9compiler import MSVCCompiler
ModuleNotFoundError: No module named 'distutils.msvc9compiler'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\pytest\venv1\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "D:\pytest\venv1\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\pytest\venv1\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\build_meta.py", line 332, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\build_meta.py", line 302, in _get_build_requires
self.run_setup()
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\build_meta.py", line 318, in run_setup
exec(code, locals())
File "<string>", line 206, in <module>
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\__init__.py", line 117, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 146, in setup
_setup_distribution = dist = klass(attrs)
^^^^^^^^^^^^
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\dist.py", line 283, in __init__
_Distribution.__init__(self, dist_attrs)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 278, in __init__
self.finalize_options()
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\dist.py", line 635, in finalize_options
ep(self)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\setuptools\dist.py", line 655, in _finalize_setup_keywords
ep.load()(self, ep.name, value)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\cffi\setuptools_ext.py", line 216, in cffi_modules
add_cffi_module(dist, cffi_module)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\cffi\setuptools_ext.py", line 69, in add_cffi_module
_add_py_module(dist, ffi, module_name)
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\cffi\setuptools_ext.py", line 153, in _add_py_module
from cffi._shimmed_dist_utils import log, mkpath
File "C:\Users\yuanj\AppData\Local\Temp\pip-build-env-i9mvvxdg\overlay\Lib\site-packages\cffi\_shimmed_dist_utils.py", line 36, in <module>
raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex
Exception: This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel 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.
这个中间折腾了好久,换了低版本的python,离谱的是同样会提示ModuleNotFoundError: No module named 'distutils.msvc9compiler
,distutils的缺失。
最后在偶然的重复安装过程中,发现换了别的镜像源居然直接安装成功了。
(venv1) PS D:\pytest> pip install anndata2ri --index-url https://mirrors.sustech.edu.cn/pypi/web/simple
Looking in indexes: https://mirrors.sustech.edu.cn/pypi/web/simple
Collecting anndata2ri
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/d5/d5/cf4e2362f106653fa67866f365796d50457e9a61e087887a06fa49dfea7a/anndata2ri-1.3.1-py3-none-any.whl (27 kB)
Collecting anndata (from anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/eb/58/2608b71280b351369b6190818c16cf90ad1d1ab2f30c2be68c8bd2c1749b/anndata-0.10.8-py3-none-any.whl (124 kB)
Collecting rpy2>=3.5.2 (from anndata2ri)
Using cached rpy2-3.5.16-py3-none-any.whl
Collecting tzlocal (from anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/97/3f/c4c51c55ff8487f2e6d0e618dba917e3c3ee2caae6cf0fbb59c9b1876f2e/tzlocal-5.2-py3-none-any.whl (17 kB)
Collecting cffi>=1.15.1 (from rpy2>=3.5.2->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/72/21/8c5d285fe20a6e31d29325f1287bb0e55f7d93630a5a44cafdafb5922495/cffi-1.17.0-cp312-cp312-win_amd64.whl (181 kB)
Collecting jinja2 (from rpy2>=3.5.2->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl (133 kB)
Collecting packaging (from rpy2>=3.5.2->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl (53 kB)
Collecting array-api-compat!=1.5,>1.4 (from anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/0f/22/8228be1d3c6d4ffcf05cd89872ce65c1317b2af98d34b9d89b247d8d49cb/array_api_compat-1.8-py3-none-any.whl (38 kB)
Collecting h5py>=3.1 (from anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/2b/b2/0ee327933ffa37af1fc7915df7fc067e6009adcd8445d55ad07a9bec11b5/h5py-3.11.0-cp312-cp312-win_amd64.whl (3.0 MB)
Collecting natsort (from anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/ef/82/7a9d0550484a62c6da82858ee9419f3dd1ccc9aa1c26a1e43da3ecd20b0d/natsort-8.4.0-py3-none-any.whl (38 kB)
Collecting numpy>=1.23 (from anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/b5/59/f6ad30785a6578ad85ed9c2785f271b39c3e5b6412c66e810d2c60934c9f/numpy-2.0.1-cp312-cp312-win_amd64.whl (16.3 MB)
Collecting pandas!=2.1.0rc0,!=2.1.2,>=1.4 (from anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/22/a5/a0b255295406ed54269814bc93723cfd1a0da63fb9aaf99e1364f07923e5/pandas-2.2.2-cp312-cp312-win_amd64.whl (11.5 MB)
Collecting scipy>1.8 (from anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/3f/72/305686527c68f33f1dd3ebdd28f53340d372b2f9e44dccaf6f92e17739d3/scipy-1.14.0-cp312-cp312-win_amd64.whl (44.5 MB)
Collecting tzdata (from tzlocal->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/65/58/f9c9e6be752e9fcb8b6a0ee9fb87e6e7a1f6bcab2cdc73f02bb7ba91ada0/tzdata-2024.1-py2.py3-none-any.whl (345 kB)
Collecting pycparser (from cffi>=1.15.1->rpy2>=3.5.2->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl (117 kB)
Collecting python-dateutil>=2.8.2 (from pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
Collecting pytz>=2020.1 (from pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/9c/3d/a121f284241f08268b21359bd425f7d4825cffc5ac5cd0e1b3d82ffd2b10/pytz-2024.1-py2.py3-none-any.whl (505 kB)
Collecting MarkupSafe>=2.0 (from jinja2->rpy2>=3.5.2->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/3f/14/c3554d512d5f9100a95e737502f4a2323a1959f6d0d01e0d0997b35f7b10/MarkupSafe-2.1.5-cp312-cp312-win_amd64.whl (17 kB)
Collecting six>=1.5 (from python-dateutil>=2.8.2->pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata->anndata2ri)
Using cached https://mirrors.sustech.edu.cn/pypi/web/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pytz, array-api-compat, tzdata, six, pycparser, packaging, numpy, natsort, MarkupSafe, tzlocal, scipy, python-dateutil, jinja2, h5py, cffi, rpy2, pandas, anndata, anndata2ri
Successfully installed MarkupSafe-2.1.5 anndata-0.10.8 anndata2ri-1.3.1 array-api-compat-1.8 cffi-1.17.0 h5py-3.11.0 jinja2-3.1.4 natsort-8.4.0 numpy-2.0.1 packaging-24.1 pandas-2.2.2 pycparser-2.22 python-dateutil-2.9.0.post0 pytz-2024.1 rpy2-3.5.16 scipy-1.14.0 six-1.16.0 tzdata-2024.1 tzlocal-5.2
然后就跑到dataspell里面去跑一些代码,发现加载包要很久很久。
其他包加载没问题,
anndata2ri
这里一直转圈,看了jupyter的状态也是没有问题,显示在运行中。到这里又怀疑是python的问题了,因为装包过程中没有错误,编辑器里面也看不出什么异常,就这个包不对。然后跑到终端里运行python发现,是没有设置R_HOME
变量,这个包引用不了,但是在dataspell里无法显示这个问题。在R里面运行
> R.home()
[1] "C:/PROGRA~1/R/R-4.4.1"
这里的输出应该是有点问题,但是已经知道是在C:\Program Files\R\R-4.4.1
了,设置环境变量之后就没问题了。