ModuleNotFoundError: No module named 'torch._C' - pytorch

I want to import the torch,but then the interpreter return this result,i have no idea how to deal with it
Traceback (most recent call last):
File "D:/Programing/tool/Python/learn_ml_the_hard_way/ML/scipy1.py", line 1, in <module>
import torch
File "D:\Programing\python\Anaconda3.5\lib\site-packages\torch\__init__.py", line 84, in <module>
from torch._C import *
ModuleNotFoundError: No module named 'torch._C'

I had the same problem and followed the instructions in this link
You can also find the torch path with this command if needed:
sudo find / -iname torch

In my case it was issue with python version, created python 3.7 environment and re-installed it. worked just fine

Initially I was running in a Conda environment got this error. Just deactivated the environment now it works.

Related

ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook'

This has been plaguing me for a while now, and I'm not sure what to do about it. I've tried modifying the init.py pyWinhook script's imports, but to no avail. Here's the whole error:
Traceback (most recent call last):
File "d:\myuser\Documents\Python\evil_programs\keylogger.py", line 6, in <module>
import pyWinhook as pyHook
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py", line 1, in <module>
from .HookManager import *
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\HookManager.py", line 1, in <module>
from . import cpyHook
ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook' (most likely due to a circular import) (C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py)
Thanks in advance
The way I fixed this is by installing Python 3.8.
Python 3.10 and 3.11 produced this issue.
I got this idea from the executable name on GitHub "pyWinhook-1.6.2.win-amd64-py3.8.exe"
Why it does not work with newer python, I have no clue.

How to deal with "ModuleNotFoundError: No module named 'setup' "

I installed the module "pyunicorn" in Ubuntu 16.04 LTS and all the dependencies but when I import the module in python 3.7.3 i get this error :
>>> import pyunicorn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda3/lib/python3.7/site-packages/pyunicorn/__init__.py", line 43, in <module>
from setup import __version__
ModuleNotFoundError: No module named 'setup'
What should i do to make it run properly???
I had this problem. I wanted to install it on Google Colab. I tried installing pyunicorn directly from Github and it worked for me. Try using following instruction:
pip install git+https://github.com/pik-copan/pyunicorn.git#egg=pyunicorn

Yaml with Python 3

I have a python3.6 virtual environment. I an trying to run some keras code and came across this error:
Traceback (most recent call last):
File "test.py", line 4, in <module>
from keras import backend as K
File "Keras-2.0.8/keras/__init__.py", line 4, in <module>
from . import activations
File "Keras-2.0.8/keras/activations.py", line 6, in <module>
from .engine import Layer
File "Keras-2.0.8/keras/engine/__init__.py", line 3, in <module>
from .topology import InputSpec
File "Keras-2.0.8/keras/engine/topology.py", line 8, in <module>
import yaml
File "Keras-2.0.8/yaml/__init__.py", line 2, in <module>
from error import *
ModuleNotFoundError: No module named 'error'
I saw a few other posts regarding this but those all suggest that the problems may be that I am using the python 2.7 version for python3. However, I don not think this is the case since I am in a python 3.6 virtual environment.
I also saw some comments about re-installing/upgrading yaml with python3.6 specifically. I thought doing a pip install in the virtual environment would fix this but it did not seem to help. Any suggestions regarding how to resolve this issue would be much appreciated.
Side Note: the code I am trying to run is test.py from this repo when I come across the error.

Jupyter Notebook in Anaconda Not Loading

Whenever I try to open Jupyter Notebook from the Anaconda GUI (or conda terminal), I get the following error:
Traceback (most recent call last):
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 10, in
import sqlite3
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\sqlite3\__init__.py", line 23, in
from sqlite3.dbapi2 import *
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\sqlite3\dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: DLL load failed: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
from notebook.notebookapp import main
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\notebookapp.py", line 86, in
from .services.sessions.sessionmanager import SessionManager
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 13, in
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I've gone so far as to uninstall Python, uninstall Anaconda, remove all python related path variables, and reinstall Anaconda with Python. This still has not worked. Is there any way to resolve this error? I've looked on many different sites but I haven't found much help.
EDIT: To add more context, it broke randomly one day and I don't have the slightest idea why. Anaconda had worked for a year or so prior. I checked both scripts that are referenced in the error prompt and they both exist in the directory.
I had the same problem.
The issue seems to arise from the missing of sqlite3.dll in the path ".\Anaconda\Dlls".(if using an env, you should put it under the env directory like ".\your env\DLLS") I solved it by simply copying that .dll file from others and put it under the path mentioned above.
You can download the sqlite3.dll from this link: sqlite3.dll

import rpy2.ipython meet error ModuleNotFoundError: No module named 'IPython'

My python version is 3.6. my OS is windows. After install rpy2 module, when I type import rpy2, got no issue. But when type import rpy2.ipython, got error as below:
>>> import rpy2.ipython
Warning (from warnings module):
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\rmagic.py", line 76
"either.")))
UserWarning: The Python package 'pandas' is strongly recommended when using `rpy2.ipython`. Unfortunately it could not be loaded, and we did not manage to load 'numpy' either.
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import rpy2.ipython
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\__init__.py", line 1, in <module>
from .rmagic import load_ipython_extension
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\rmagic.py", line 81, in <module>
from IPython.core.displaypub import publish_display_data
ModuleNotFoundError: No module named 'IPython'
Can help to figure out what's issue??
It seems that you are missing Ipython and pandas. Installing them should resolve your issue.
Run "pip install ipython" to install Ipython and run "pip install pandas" to install pandas.
Hopefully, this will solve your problem.
Happy Coding ~

Resources