21

I'm trying to use Apex and whenever I try to import it (or anything involving it) I get the following traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/anaconda3/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)

I have the Pyramid library installed and importing that causes no issues. My Python version is 3.8.5 and my OS is Ubuntu 18.04.5.

I've tried searching online but haven't been able to find a satisfactory solution and was hoping to know if anyone who is familiar would be able to provide some tips on what the problem may be and what I can do. Thanks.

2
  • It looks like you did not install a compatible version of pyramid into your virtual environment. Apex itself was last uploaded 2013-03-05, and is no longer actively maintained, so I highly doubt it is still compatible with the latest Pyramid 2.0. What do you want to use Apex for? I could suggest alternatives that are maintained, or you can look at trypyramid.com/extending-pyramid.html for add-ons. Commented Mar 14, 2021 at 6:30
  • Yeah I didn't realize that Apex wasn't being actively maintained. In fact, according to posts on the Discuss PyTorch forum like this one, PyTorch has a native AMP thing as well. I'm not necessarily trying to use Apex, but most of the baseline models that I'm trying to run were implemented using it. I guess I could try refactoring it into PyTorch.
    – Sean
    Commented Mar 14, 2021 at 6:32

6 Answers 6

45

I get the same issue if I use pip install apex.

It turns out that apex on pypi has nothing to do with NVIDIA's apex and is a totally unrelated, really old package.

To install NVIDIA's apex do:

git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir \
--global-option="--cpp_ext" --global-option="--cuda_ext" ./

For more info see doc.

3
  • one might face compilation error while installing using git repo as torch currently is using CUDA 10.2 version just sharing the insight which I found during installation. so either downgrade or updgrade to CUDA 10.2 version to make this work. Commented Aug 22, 2021 at 14:05
  • @AnkitKumarNamdeo, pytorch has a whole variety of builds and not just cu-102, please see: pytorch.org/get-started/locally/#start-locally
    – stason
    Commented Aug 22, 2021 at 20:41
  • 1
    Also if you're using the same major cuda version, but minor versions mismatch, see this workaround: github.com/NVIDIA/apex/issues/988#issuecomment-726343453
    – stason
    Commented Aug 22, 2021 at 20:43
15

The code below worked for me

git clone https://github.com/NVIDIA/apex
cd apex
python setup.py install
0
7

This will work:

pip uninstall apex
2

use apex/requirements.txt
The code below worked for me

git clone https://github.com/NVIDIA/apex
cd apex
pip install -r requirements.txt
pip install -v --disable-pip-version-check --no-cache-dir ./
1

Below code has worked for me in colab instance

!git clone https://github.com/NVIDIA/apex
%cd apex
!python3 setup.py install
0
0

Updated March 2023: Created new virtual environment with corrected python version

conda create --name RSSC python==3.7.10
git clone https://github.com/NVIDIA/apex
cd apex
pip install -r requirements.txt
pip install -v --disable-pip-version-check --no-cache-dir ./

Not the answer you're looking for? Browse other questions tagged or ask your own question.