openopt / chop

CHOP: An optimization library based on PyTorch, with applications to adversarial examples and structured neural network training.
http://openo.pt/chop
Other
76 stars 14 forks source link

Import error when install chop on Colab #50

Closed GeoffNN closed 3 years ago

GeoffNN commented 3 years ago

When running !python -m pip install git+https://github.com/openopt/chop on a Google colab, I get the following error:

<ipython-input-2-f345500ab750> in <module>()
----> 1 import chop

1 frames
/usr/local/lib/python3.7/dist-packages/chop/stochastic.py in <module>()
     14 import torch
     15 from torch.optim import Optimizer
---> 16 from chop import utils
     17 import numpy as np
     18 

ImportError: cannot import name 'utils' from 'chop' (/usr/local/lib/python3.7/dist-packages/chop/__init__.py)

@fabianp any clue why this could happen?

fabianp commented 3 years ago

just a guess, but maybe it should use relative imports?

On Wed, Mar 3, 2021 at 7:42 PM Geoffrey Negiar notifications@github.com wrote:

When running !python -m pip install git+https://github.com/openopt/chop on a Google colab, I get the following error:

in () ----> 1 import chop 1 frames /usr/local/lib/python3.7/dist-packages/chop/stochastic.py in () 14 import torch 15 from torch.optim import Optimizer ---> 16 from chop import utils 17 import numpy as np 18 ImportError: cannot import name 'utils' from 'chop' (/usr/local/lib/python3.7/dist-packages/chop/__init__.py) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or unsubscribe .
fabianp commented 3 years ago

or not. we use the same import type in copt and it seems to work there

On Thu, Mar 4, 2021 at 7:20 AM Fabian Pedregosa pedregosa@google.com wrote:

just a guess, but maybe it should use relative imports?

On Wed, Mar 3, 2021 at 7:42 PM Geoffrey Negiar notifications@github.com wrote:

When running !python -m pip install git+https://github.com/openopt/chop on a Google colab, I get the following error:

in () ----> 1 import chop 1 frames /usr/local/lib/python3.7/dist-packages/chop/stochastic.py in () 14 import torch 15 from torch.optim import Optimizer ---> 16 from chop import utils 17 import numpy as np 18 ImportError: cannot import name 'utils' from 'chop' (/usr/local/lib/python3.7/dist-packages/chop/__init__.py) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or unsubscribe .
GeoffNN commented 3 years ago

This is very strange.

The following sequence works, and does not yield any import errors

git clone https://github.com/openopt/chop.git
cd chop
pip install .

But the following doesn't work:

pip install git+https://github.com/openopt/chop.git

The version on PyPi doesn't work either:

pip install chop-pytorch

....

GeoffNN commented 3 years ago

Actually the last one works on my machine, just not on colab...

GeoffNN commented 3 years ago

Fixed!