天天看點

在導入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/