ModuleNotFoundError: python import extern module - python

I struggle with importing Pillow in my python code.
My import statements:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pillow
I use an local Anaconda interpreter (Anaconda 3) where I installed pillow:
conda install -c anaconda pillow
If I check with conda list there is a pillow-package...
Pycharm still throws: ModuleNotFoundError: No module named 'pillow'
There were no errors during pillow installation...
I tried restarting pycharm, reboot, uninstall / reinstalling pillow
I have no further idea what I can do, would be great if someone can help me :)
I'm working with pycharm 2017.3 on Windows 7 (64bit)
Kind regards, Lukas

Related

Spyder imports numpy from the wrong python environment

I want to import opencv in spyder using the IPython console. However, when I try to do this, I get an import error on numpy.
Platform: Jetson xavier
Spyder version: 3.2.6
I'm using 'virtualenv' to manage my virtual environment.
What works:
I can import cv2 in python using a bash terminal. Steps to reproduce:
Activate my virtual environment by running source my_env/bin/activate
Start python by running python
Import opencv by running import cv2
Success
I use spyder as my IDE and I want to import opencv in a python script run by spyder. However, when I run import cv2 I get ImportError: numpy.core.multiarray failed to import. Steps to reproduce:
In spyder in preferences set the Python interpreter to the one from my virtual environment (~/my_env/bin/python3)
Restart IPython console
Type import cv2 in the IPython console
I get the ImportError: numpy.core.multiarray failed to import
I already tried updating numpy, as recommended by ImportError: numpy.core.multiarray failed to import but this did not work.
Update
In spyder I can import numpy manually, and using inspect.getfile(numpy) tells me that spyder imported numpy from /usr/lib/python3/dist-packages/numpy/__init__.py, While it sohuld import numpy from ~/my_env/lib/python3.6/site-packages/numpy. Why is spyder importing numpy from the wrong environment?

Cannot import matplotlib on Spyder after conda installation

I installed matplotlib on Anaconda Prompt with conda install -c conda-forge matplotlib.
However, when I run import matplotlib.pyplot as plt on Spyder 4.1.5 (with Python 3.7), I got an error message:
ModuleNotFoundError: No module named 'matplotlib.pyplot'
Before getting this error message, I installed matplotlib_scalebar with conda install -c conda-forge matplotlib-scalebar. I had no issue importing matplotlib.pyplot before this, and I suspect that installing this might have caused the problem.
Under C:\ProgramData\Anaconda3\Lib\site-packages, I have folders with the following names:
matplotlib
matplotlib-3.0.2.dist-info
matplotlib-3.3.2.dist-info
I'm not sure if having different folders (3.0.2 and 3.3.2) is an issue here.
How can I fix this No module issue?

ImportError: No module named scenedetect on Linux Ubuntu

I'm trying to use pyscenedetect library on python for videos but I get this error when using the python interface and when I use the command line interface I get the error "ModuleNotFoundError: No module named 'cv2'"
even though I believe I installed both correctly according to the documentations.
I have trying to look for different ways to import opencv for the second error but to no avail. As for the first error i can't find any answers to my problem.
import cv2
import numpy as numpy
import os
import scenedetect
from scenedetect.video_manager import VideoManager
from scenedetect.scene_manager import SceneManager
from scenedetect.frame_timecode import FrameTimecode
from scenedetect.stats_manager import StatsManager
from scenedetect.detectors import ContentDetector
If you have pip you can try
pip install opencv-python
If you have anaconoda, you can try
conda install -c conda-forge opencv
it's probable that you installed it on a different python installation in your PC.
To know where your python installation is you can launch python and:
import sys
sys.path
To get the list of everything you have installed you can:
pip freeze > installed_modules.txt
Try only running
import cv2
So that you can test it
I found the problem. As Ivan was pointing out, the problem was with openCV.
I used the following command:
sudo apt install python3-opencv

ModuleNotFoundError: No module named 'websocket' even though I installed pip install websocket

I am trying to run some code that has 'import websocket' however I am getting the error: ModuleNotFoundError: No module named 'websocket'
I have Python 3.7.3 and I am running in Spyder (if that makes a difference).
So from other questions/answers I found on here, in my cmd I ran pip install websocket and then also pip install websocket-client when the first one didn't run.
I am still getting the ModuleNotFoundError. Does it matter the location/folder of the code or where I install the pip command in cmd?
My python code starts with these import statements:
import json
import websocket
import traceback
import helper
import ssl
import time as time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
In cmd I ran:
C:\Users\myname>pip install websocket
and also:
C:\Users\myname>pip install websocket-client
The error I am getting is:
File "C:/Users/micki/Downloads/Derbit-Volatility-Visulization-master/Derbit-Volatility-Visulization-master/Volatility Surface Class.py", line 2, in <module>
import websocket
ModuleNotFoundError: No module named 'websocket'
Not sure, as you did not cover how you installed and are using Spyder, though I think it is probably an issue with your environment. You might also find that you are missing the module "helper" as well. There's two easy options as follows:
If you installed and are using Spyder via conda or anaconda, follow their documentation on installing websocket-client to the correct environment found here.
The second option (the preferred option IMHO, as you can use any IDE or text editor going forward), regardless of how you installed Spyder, would be to create a python virtual environment python3 -m venv /path/to/new/virtual/environment, pip install all your dependencies in said environment, then link Spyder's interpreter to the interpereter that was installed when you made the environment. In Spyder, go to Tools -> Preferences -> Python interpreter -> check the "Use the following Python interpreter:" radio button and enter the path to the interpreter from the environment you just created. For reference, see docs on making and using a python venv here.
If the websocket and websocket-client doesn't work, try:
pip install websocket_client
This solved my issue:
sudo pip install websocket-client

Cannot import name cbook in jupyter

I have matplotlib-2.2.3 installed. When I used matplotlib in jupyter, it throws the following error:
ImportError: cannot import name cbook in jupyter
All is OK when I run the code in PyCharm. I used python 2.7 and I have tried many suggestions like that in ImportError: cannot import name cbook but none worked.
I finally found the solution that downgrade the matplotlib and six, and that solves my question.
pip install six==1.10.0
pip install matplotlib==2.0.2

Categories