Undefined symbol: _Py_ZeroStruct

Although I have successfully installed pytorch with both python2.7 and python3, when I run a program, I get this error:

$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import torch
  File "/home/mnaderan/.local/lib/python3.6/site-packages/torch/__init__.py", line 81, in <module>
    from torch._C import *
ImportError: /home/mnaderan/.local/lib/python3.6/site-packages/torch/lib/libtorch_python.so: undefined symbol: _Py_ZeroStruct
Segmentation fault (core dumped)

The output of python3 setup.py install --user is here and here.