PyTorch-Encoding icon indicating copy to clipboard operation
PyTorch-Encoding copied to clipboard

Cannot import encoding

Open OasisYang opened this issue 6 years ago • 32 comments

Hi, I can run "python setup.py install" with no errors, but when i try to "import encoding". I got the error like this. Could you help me with that, thanks. image

OasisYang avatar Jun 13 '18 03:06 OasisYang

Please install ninja 1.8.2 by following the instructions https://www.claudiokuenzler.com/blog/756/install-newer-ninja-build-tools-ubuntu-14.04-trusty#.WxYrvFMvzJw

zhanghang1989 avatar Jun 13 '18 03:06 zhanghang1989

I installed the ninja 1.8.2 by the instructions you mentioned, but got the same error @zhanghang1989.

OasisYang avatar Jun 19 '18 13:06 OasisYang

I have got the same error, and I changed ['ninja', '-v'] to ['ninja', '--v'],but the main error also exists, when I try "import encoding", I got error " ImportError: No module named 'enclib_cpu' ", it seems must have one of this image but I have none. I have run "python setup.py install" with no errors and my ninja version is 1.8.2. @zhanghang1989 @OasisYang Have you solved it?

liyingying05 avatar Jun 20 '18 06:06 liyingying05

Are you using the PyTorch master branch?

zhanghang1989 avatar Jun 20 '18 13:06 zhanghang1989

@zhanghang1989 I am having the same issues described above. At first I had the RuntimeError: Error building extension 'enclib_cpu' just like @OasisYang described. Then I tried replacing ['ninja', '-v'] by ['ninja', '--v'] like @liyingying05 did, and also had the ImportError: No module named 'enclib_cpu'.

I have ninja 1.8.2 installed. I pip-installed torch-encoding with no errors. Also tried installing via setup.py, which worked fine. I'm working on the Pytorch master branch. Do any of you have solved it?

vribeiro1 avatar Jun 24 '18 20:06 vribeiro1

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

liyingying05 avatar Jul 05 '18 10:07 liyingying05

I have successful installed pytorch 0.5 and ninja 1.8.2,however when I import encoding, there has also problems.

`Traceback (most recent call last): File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 742, in _build_extension_module ['ninja', '-v'], stderr=subprocess.STDOUT, cwd=build_directory) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/subprocess.py", line 376, in check_output **kwargs).stdout File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/subprocess.py", line 468, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/init.py", line 13, in from . import nn, functions, dilated, parallel, utils, models, datasets File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/nn/init.py", line 12, in from .encoding import * File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/nn/encoding.py", line 18, in from ..functions import scaledL2, aggregate, pairwise_cosine File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/functions/init.py", line 2, in from .encoding import * File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/functions/encoding.py", line 14, in from .. import lib File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/init.py", line 20, in ], build_directory=gpu_path, verbose=False) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 496, in load with_cuda=with_cuda) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 664, in _jit_compile _build_extension_module(name, build_directory) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 748, in _build_extension_module name, error.output.decode())) RuntimeError: Error building extension 'enclib_gpu': [1/4] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu -o encoding_kernel.cuda.o FAILED: encoding_kernel.cuda.o /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu -o encoding_kernel.cuda.o /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(315): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(341): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(364): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(391): error: class "at::Context" has no member "getCurrentCUDAStream"

4 errors detected in the compilation of "/tmp/tmpxft_00005f49_00000000-6_encoding_kernel.cpp1.ii". [2/4] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu -o syncbn_kernel.cuda.o FAILED: syncbn_kernel.cuda.o /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu -o syncbn_kernel.cuda.o /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(183): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(217): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(249): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(272): error: class "at::Context" has no member "getCurrentCUDAStream"

4 errors detected in the compilation of "/tmp/tmpxft_00005f4a_00000000-6_syncbn_kernel.cpp1.ii". [3/4] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu -o roi_align_kernel.cuda.o FAILED: roi_align_kernel.cuda.o /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu -o roi_align_kernel.cuda.o /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(373): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(373): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(420): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(420): error: class "at::Context" has no member "getCurrentCUDAStream"

4 errors detected in the compilation of "/tmp/tmpxft_00005f4b_00000000-6_roi_align_kernel.cpp1.ii". ninja: build stopped: subcommand failed.`

XindyTT avatar Jul 23 '18 09:07 XindyTT

Please install ninja 1.8.2 by following the instructions https://www.claudiokuenzler.com/blog/756/install-newer-ninja-build-tools-ubuntu-14.04-trusty#.WxYrvFMvzJw

zhanghang1989 avatar Jul 23 '18 16:07 zhanghang1989

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version before?

XindyTT avatar Jul 24 '18 08:07 XindyTT

Thanks a lot @XindyTT ! I will update the repo in next release.

zhanghang1989 avatar Jul 24 '18 16:07 zhanghang1989

use pytorch=0.4.1 will be ok. My python version is 3.6.7.

fanglw avatar Oct 29 '18 12:10 fanglw

This issue should have been fixed by previous PR.

zhanghang1989 avatar Nov 01 '18 23:11 zhanghang1989

I'm also getting this error: ImportError: No module named 'enclib_cpu'. I did a source install from the Pytorch master branch and installed ninja 1.8.2 as per the link above. Any suggestions?

thompa2 avatar Nov 13 '18 15:11 thompa2

Maybe it is related to this https://github.com/zhanghang1989/PyTorch-Encoding/issues/140#issuecomment-438373706

zhanghang1989 avatar Nov 13 '18 18:11 zhanghang1989

i have met the same problem. i have try it on pytorch0.4.1 and pytorch1.0, and also rename torch.h to extension.h, but i still cannot solve it. if anyone solve it?

chauhochow avatar Nov 28 '18 15:11 chauhochow

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version b

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

Hello. What do you mean by using Pytroch master? Do I need uninstall the current Pytorch and install a new version?

henanjun avatar Dec 30 '18 11:12 henanjun

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version b

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

Hello. What do you mean by using Pytroch master? Do I need uninstall the current Pytorch and install a new version?

master is the branch of Pytorch in git. However, the API and variable may change if pytorch's version update. I tried the repo in June, where the master of pytorch is version 0.5. And now the version may be higher.

XindyTT avatar Dec 31 '18 03:12 XindyTT

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version b

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

Hello. What do you mean by using Pytroch master? Do I need uninstall the current Pytorch and install a new version?

master is the branch of Pytorch in git. However, the API and variable may change if pytorch's version update. I tried the repo in June, where the master of pytorch is version 0.5. And now the version may be higher.

I see. Thanks for your kind reply.

henanjun avatar Jan 02 '19 03:01 henanjun

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

hi,Could you tell me how you solved this problem?ubuntu==16.04,python==3.5,gcc==5.4.0 cuda==9.0 torch-encoding Version is 1.0.0

andrewwyl avatar Nov 12 '19 09:11 andrewwyl

same problem with torchvision-0.5.0 pytorch-1.4.0 and ninjia 1.8.2

chenerg avatar May 04 '20 03:05 chenerg

Hi, did you follow the instructions at https://hangzhang.org/PyTorch-Encoding/notes/compile.html

I suggest using the latest anaconda with CUDA 10.0 on ubuntu 16.04.

zhanghang1989 avatar May 04 '20 04:05 zhanghang1989

it doesn't work ,i have tried No module named 'enclib_gpu' @zhanghang1989

qiaoyaya2011 avatar Jul 05 '20 10:07 qiaoyaya2011

do you have saved this problem? @OasisYang

qiaoyaya2011 avatar Jul 05 '20 10:07 qiaoyaya2011

@zhanghang1989 I am having the same issues described above. At first I had the RuntimeError: Error building extension 'enclib_cpu' just like @OasisYang described. Then I tried replacing ['ninja', '-v'] by ['ninja', '--v'] like @liyingying05 did, and also had the ImportError: No module named 'enclib_cpu'.

I have ninja 1.8.2 installed. I pip-installed torch-encoding with no errors. Also tried installing via setup.py, which worked fine. I'm working on the Pytorch master branch. Do any of you have solved it?

i also meet this problem,have you solved it

qiaoyaya2011 avatar Jul 05 '20 10:07 qiaoyaya2011

what's the mean of PR @zhanghang1989

qiaoyaya2011 avatar Jul 05 '20 10:07 qiaoyaya2011

same problem with torchvision-0.5.0 pytorch-1.4.0 and ninjia 1.8.2

me too

qiaoyaya2011 avatar Jul 05 '20 10:07 qiaoyaya2011

Hi, did you follow the instructions at https://hangzhang.org/PyTorch-Encoding/notes/compile.html

I suggest using the latest anaconda with CUDA 10.0 on ubuntu 16.04.

it doesn't work

qiaoyaya2011 avatar Jul 05 '20 10:07 qiaoyaya2011

Please use pytorch 1.4.0. PyTorch 1.5 is not supported yet.

zhanghang1989 avatar Jul 05 '20 20:07 zhanghang1989

I am facing an issue like this during my installation of Pytorch_Encoding. I am trying to run this module in Windows. And I am using Anaconda for this purpose. Could someone of you please give me a detailed set of instructions as to how I properly install it and resolve the issue that I captured below:

This is the error I am getting for the installation:

INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This could take a while. INFO: pip is looking at multiple versions of torch-encoding to determine which version is compatible with other requirements. This could take a while. ERROR: Cannot install torch-encoding and torch-encoding==1.2.2b20210226 because these package versions have conflicting dependencies.

The conflict is caused by: torch-encoding 1.2.2b20210226 depends on torch>=1.4.0 torchvision 0.5.0 depends on torch==1.4.0

To fix this you could try to:

  1. loosen the range of package versions you've specified
  2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

diwamanic avatar Feb 26 '21 09:02 diwamanic

Please uninstall all the existing versions torch-encoding library in your machine. Then follow the instructions: https://hangzhang.org/PyTorch-Encoding/notes/compile.html

zhanghang1989 avatar Feb 26 '21 16:02 zhanghang1989