20

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.

Sean
  • 2,890
  • 8
  • 36
  • 78
  • 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 https://trypyramid.com/extending-pyramid.html for add-ons. – Steve Piercy Mar 14 '21 at 06: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](https://discuss.pytorch.org/t/using-apex-amp-with-pytorch-optimizers-causes-attribute-error/114648/2?u=seankala), 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 Mar 14 '21 at 06:32

6 Answers6

38

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.

stason
  • 5,409
  • 4
  • 34
  • 48
  • 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. – Ankit Kumar Namdeo Aug 22 '21 at 14:05
  • @AnkitKumarNamdeo, pytorch has a whole variety of builds and not just cu-102, please see: https://pytorch.org/get-started/locally/#start-locally – stason Aug 22 '21 at 20:41
  • Also if you're using the same major cuda version, but minor versions mismatch, see this workaround: https://github.com/NVIDIA/apex/issues/988#issuecomment-726343453 – stason Aug 22 '21 at 20:43
9

The code below worked for me

git clone https://github.com/NVIDIA/apex
cd apex
python setup.py install
sammens19
  • 161
  • 2
  • 4
5

This will work:

pip uninstall apex
Greg Tarr
  • 124
  • 1
  • 5
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 ./
0

Below code has worked for me in colab instance

!git clone https://github.com/NVIDIA/apex
%cd apex
!python3 setup.py install
Somex Gupta
  • 177
  • 2
  • 7
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 ./
Khawar Islam
  • 2,556
  • 2
  • 34
  • 56