天天看点

在导入NVIDIA的apex库时报错 ImportError cannot import name ‘UnencryptedCookieSessionFactoryConfig‘ from在导入NVIDIA的apex库时报错 ImportError: cannot import name ‘UnencryptedCookieSessionFactoryConfig’ from ‘pyramid.session’ (unknown location)

在导入NVIDIA的apex库时报错 ImportError: cannot import name ‘UnencryptedCookieSessionFactoryConfig’ from ‘pyramid.session’ (unknown location)

报错

在使用NVIDIA的apex库时报错 ImportError: cannot import name ‘UnencryptedCookieSessionFactoryConfig’ from ‘pyramid.session’ (unknown location)

笔者一开始是使用的pip直接来安装apex:

pip install apex
           

但是在运行时报错:

Traceback (most recent call last):
  File "main.py", line 10, in <module>
    import apex
  File "/home/ps/anaconda3/envs/JJ_env/lib/python3.8/site-packages/apex/__init__.py", line 13, in <module>
    from pyramid.session import UnencryptedCookieSessionFactoryConfig
ImportError: cannot import name 'UnencryptedCookieSessionFactoryConfig' from 'pyramid.session' (unknown location)
           

经调查,原因是pip直接安装的apex只是和我们想要安装的NVIDIA的apex库重名,但其实根本不是一回事儿。、

解决方案

从NVIDIA的github安装apex库

git clone https://github.com/NVIDIA/apex
cd apex

# 同时安装C++扩展
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
 
# Apex 同样支持 Python-only build (required with Pytorch 0.4) via
 
pip install -v --no-cache-dir ./
           

笔者使用带C++扩展的完全安装时同样会报错,使用仅python安装时显示成功。

前者关键报错信息为:

ERROR: Command errored out with exit status 1: /users4/zsun/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-v0deounv/setup.py'"'"'; __file__='"'"'/tmp/p
ip-req-build-v0deounv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' --cpp_e
xt --cuda_ext install --record /tmp/pip-record-rce1cb4d/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
           

参考:

https://stackoverflow.com/questions/66610378/unencryptedcookiesessionfactoryconfig-error-when-importing-apex

https://blog.csdn.net/ccbrid/article/details/103207676/