Giter Site home page Giter Site logo

Comments (31)

apaszke avatar apaszke commented on April 27, 2024 180

@szagoruyko Could you please try opening torch in any directory other than repo's root? It's trying to load the torch dir instead of the python package and gives you this error.

from pytorch.

LinMaris avatar LinMaris commented on April 27, 2024 3

could you tell me whats the meaning of ' opening torch in any directory other than repo's root '

from pytorch.

soumith avatar soumith commented on April 27, 2024 2

hahaha

from pytorch.

b1zantine avatar b1zantine commented on April 27, 2024 2

made the same mistake 😄

from pytorch.

soumith avatar soumith commented on April 27, 2024

@apaszke can you add 16.04 to the build matrix

from pytorch.

soumith avatar soumith commented on April 27, 2024

16.04 is not supported looks like it. i'll try to setup an ec2 based contbuild tomorrow

from pytorch.

szagoruyko avatar szagoruyko commented on April 27, 2024

@soumith the error on 14.04 is the same

from pytorch.

szagoruyko avatar szagoruyko commented on April 27, 2024

@apaszke works :P so lame

from pytorch.

phenixcx avatar phenixcx commented on April 27, 2024

Hi, I met the same problem when installing PyTorch with Python 2.7.13, centos 7 and Anaconda 4.3.0 (64-bit). I also use '/root/anaconda2/bin/python' to launch python as soumith taught me in #574. Finally, it met the same problem. In addition, I installed torch 7 in another package before installing pytorch. torch can be launched standalone with 'th' in the pytorch package. Would you mind give me a hint?

The installing way is written as follows:
git clone https://github.com/pytorch/pytorch
pip install -r requirements.txt
python setup.py install

After that, the system told me that PyTorch is installed. Then I wrote down 'python' in the prompt command line. At last, 'import torch' was entered in the python command line. Unfortunately , I got the following information:
Traceback (most recent call last):
File "", line 1, in
File "torch/init.py", line 45, in
from torch._C import *
ImportError: No module named _C

The package /usr/lib/python2.7/site-packages has no torch package. The pytorch has a package torch, and has the following files:
[root@AliHPC-M40-434 torch]# ls -ll
total 236
drwxr-xr-x 3 root root 150 Feb 10 11:54 autograd
drwxr-xr-x 3 root root 48 Feb 10 11:54 backends
drwxr-xr-x 9 root root 4096 Feb 10 11:54 csrc
drwxr-xr-x 2 root root 109 Feb 10 11:54 cuda
drwxr-xr-x 2 root root 83 Feb 10 11:54 distributed
-rw-r--r-- 1 root root 2218 Feb 10 11:54 functional.py
-rw-r--r-- 1 root root 7768 Feb 10 11:54 init.py
-rw-r--r-- 1 root root 8762 Feb 10 13:49 init.pyc
drwxr-xr-x 4 root root 61 Feb 10 11:54 legacy
drwxr-xr-x 15 root root 4096 Feb 10 12:00 lib
drwxr-xr-x 2 root root 93 Feb 10 11:54 multiprocessing
drwxr-xr-x 6 root root 4096 Feb 10 11:54 nn
drwxr-xr-x 2 root root 4096 Feb 10 11:54 optim
-rw-r--r-- 1 root root 12581 Feb 10 11:54 serialization.py
drwxr-xr-x 2 root root 32 Feb 10 11:54 sparse
-rw-r--r-- 1 root root 3354 Feb 10 11:54 storage.py
-rw-r--r-- 1 root root 33716 Feb 10 11:54 _tensor_docs.py
-rw-r--r-- 1 root root 17009 Feb 10 11:54 tensor.py
-rw-r--r-- 1 root root 10346 Feb 10 11:54 _tensor_str.py
drwxr-xr-x 2 root root 71 Feb 10 11:55 _thnn
-rw-r--r-- 1 root root 99370 Feb 10 11:54 _torch_docs.py
drwxr-xr-x 6 root root 145 Feb 10 11:54 utils
-rw-r--r-- 1 root root 2532 Feb 10 11:54 _utils.py
-rw-r--r-- 1 root root 2895 Feb 10 13:49 _utils.pyc

from pytorch.

soumith avatar soumith commented on April 27, 2024

you dont have to report it twice, i will reply on the other thread

from pytorch.

phenixcx avatar phenixcx commented on April 27, 2024

Thank you very much @soumith . I will not repeat it next time.

from pytorch.

dkkim93 avatar dkkim93 commented on April 27, 2024

@LinMaris, If your repo's root (for example) is in /home/dongki/library/pytorch, then please move to a different directory other than the repo's root (e.g., cd /home/dongki/) and open the torch. :-)

from pytorch.

huangsiyuzhoujie avatar huangsiyuzhoujie commented on April 27, 2024

i use import torch and appear torch/_C.cpython-35m-x86_64-linux-gnu.so: undefined symbol: THManageeSharedAllocator thankyou

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

@apaszke I just trying to build the documentation in pytorch/docs and I get this message

cd ~/pytorch/docs
make html

Traceback (most recent call last):
  File "source/scripts/build_activation_images.py", line 8, in <module>
    import torch.nn.modules.activation
  File "/home/ubuntu/pytorch/torch/__init__.py", line 84, in <module>
    from torch._C import *
ImportError: No module named _C
Makefile:17: recipe for target 'figures' failed
make: *** [figures] Error 1

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

Could be related to this #5490 ?
I am building in a container

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

Sorry for the inconvenience, I solved overriding the Makefile PYCMD variable

:D

from pytorch.

CedricBeaulac avatar CedricBeaulac commented on April 27, 2024

@szagoruyko Could you please try opening torch in any directory other than repo's root? It's trying to load the torch dir instead of the python package and gives you this error.

I'm having this issue, can you explain what it means and how to ''solve'' it ?

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

@CedricBeaulac what is the script you using to build it that gives you that error ?

from pytorch.

CedricBeaulac avatar CedricBeaulac commented on April 27, 2024

The script ? A simple

import torch

produces the following error

ModuleNotFoundError: No module named 'torch._C'

I've had extensive issues distinguishing bettwen the path, the interpreter path and how pip installs and conda installs interact with all of these things.

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

Hi again @CedricBeaulac ,

I meant the script are you using to build pytorch from the source. Because this kind of problem is not a concern if you are just installing it from pip or conda. the problem lies on how are you building and installing your package.

from pytorch.

reRaymond avatar reRaymond commented on April 27, 2024

I'm really running a big file but sadly problem"no module named torch._c"showed up.I just copied "pytorch " from a friend's laptop,but still comes the problem.Hope someone to give me the solution!!

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

Hi @reRaymond ,

Did your friend build pytorch on his laptop ?
If so you will need to have the same structure and packages installed.

from pytorch.

LJYlearner avatar LJYlearner commented on April 27, 2024

i aslo met the same problem: from torch._C import * ModuleNotFoundError: No module named 'torch._C'
i install anconda3 and i built a virtual environment named tensorflow. Then i installed torch,but it seems to install on the D:\Anconda3_4.4.0\Lib\site-packages,not in my Virtual environment tensorflow.So i install again in the D:\Anconda3_4.4.0\envs\tensorflow\Lib\site-packages.But when i import torch In this directory it met the problem.However,i import torch in other directory then it success! Please help me how to solve this. i want use import torch in my Virtual environment.

from pytorch.

reRaymond avatar reRaymond commented on April 27, 2024

Hi @reRaymond ,

Did your friend build pytorch on his laptop ?
If so you will need to have the same structure and packages installed.

Thank you sooooo much ,i've got my problem solved,using a right version.thank you again!!

from pytorch.

reRaymond avatar reRaymond commented on April 27, 2024

i aslo met the same problem: from torch._C import * ModuleNotFoundError: No module named 'torch._C'
i install anconda3 and i built a virtual environment named tensorflow. Then i installed torch,but it seems to install on the D:\Anconda3_4.4.0\Lib\site-packages,not in my Virtual environment tensorflow.So i install again in the D:\Anconda3_4.4.0\envs\tensorflow\Lib\site-packages.But when i import torch In this directory it met the problem.However,i import torch in other directory then it success! Please help me how to solve this. i want use import torch in my Virtual environment.

well,i've got my problem solved by now.but i'm not using a virtual environment.here's my advice for you.First thing to know is that torch version has to be suitable,which means,you'll need to visit https://pytorch.org.and download your one,attention to those choices while download.hope you get it through,because it's such a torment

from pytorch.

LJYlearner avatar LJYlearner commented on April 27, 2024

@reRaymond ,i use the correct version.It may not related to the problem. But,thank you very much!

from pytorch.

cyberwillis avatar cyberwillis commented on April 27, 2024

i aslo met the same problem: from torch._C import * ModuleNotFoundError: No module named 'torch._C'
i install anconda3 and i built a virtual environment named tensorflow. Then i installed torch,but it seems to install on the D:\Anconda3_4.4.0\Lib\site-packages,not in my Virtual environment tensorflow.So i install again in the D:\Anconda3_4.4.0\envs\tensorflow\Lib\site-packages.But when i import torch In this directory it met the problem.However,i import torch in other directory then it success! Please help me how to solve this. i want use import torch in my Virtual environment.

Hi
sorry but, are you sure the environment was enable before installing or using torch package ?
Your description is very confuse and lacking so many details.

from pytorch.

gauravgoenka avatar gauravgoenka commented on April 27, 2024

@apaszke works :P so lame

what was the exact thing that you did to resolve this issue>??

from pytorch.

gauravgoenka avatar gauravgoenka commented on April 27, 2024

I am getting the same error:
from torch._C import *
ModuleNotFoundError: No module named 'torch._C'

I am on a windows system.
My torch packages are in "D:\Anaconda3_32\Lib\torch"

what should i do??

from pytorch.

Rio56 avatar Rio56 commented on April 27, 2024

I am getting the same error:
from torch._C import *
ModuleNotFoundError: No module named 'torch._C'

I am on a windows system.
My torch packages are in "D:\Anaconda3_32\Lib\torch"

what should i do??

I meet the same error and I use windows too. Have you figure it out? If you find the solution, can you send a email to [email protected]? Thank you very much. Maybe we will meet the same problems in the future.

from pytorch.

Rajan244 avatar Rajan244 commented on April 27, 2024

import torch

NameError Traceback (most recent call last)
in
----> 1 import torch

C:\ProgramData\Anaconda3\lib\site-packages\torch_init_.py in
227
228
--> 229 all += [name for name in dir(C)
230 if name[0] != '
' and
231 not name.endswith('Base')]

NameError: name '_C' is not defined

I am having this error during importing the torch package. Even I search a couple of solutions from the internet. Mostly all said the same "the problem is that you have a folder called torch in the same directory which is being picked up. Do this: cd .. (to change directory), and then start python and import torch, it should work."
But I not getting which directory to.. also I change a couple of paths but it not working. Any idea??????
@soumith

from pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.