VSC does not import installed python libraries - python

I recently got a new computer and installed VSC as well as the official python on it. I installed some extra libraries for python on it with pip but whenever I want to run a script it gives me the error: ModuleNotFoundError: No module named 'numpy', or any other library installed afterwards. The libraries that come with python do work.
When I run the same script in IDLE for example, all the libraries are found and it works fine, but I would like to be able to code in VSC.
For example:
import numpy as np
import pygame as pg
import time
Rest of the code...
The error occurs right when it tries to import the libraries.
Any ideas on what might be causing the problem?

Related

import rpy2 but can not import rpy2.robjects when changing start folders

The Current problem I am looking into is described below:
My computer is Win10, I installed only one anaconda 3.5.3 on it. Using where python there is only one python in my computer.
I downloaded a rpy2python wheel file from the uefi website, and install that using pip install.
When I import rpy2 in C disk, it is already fine, import rpy2,import rpy2.robjects are all OK.
But when I import rpy2 in my own project, I can only first import rpy2, when I import rpy2.robjects,the program says can not find rpy2 module.
Finally I found the problem is that in my project, I occasionaly established an rpy2.py file, when I first import rpy2, it where automatically create an rpy2.pycache folder, secondly when I import rpy2.robjects, Of Course the computer can not find an rpy2.robjects.
Just Keep a track of my problem.
You'll want to check the Python documentation about import rules for modules. By default, having a file called rpy2.py in the working directory for your Python code will cause import rpy2 to find this one rather that the rpy2 package.
The easiest fix is probably to rename your module rpy2.py into something else.

Cannot import gtk in pycharm

I'm using pycharm. I got one project and I have a problem to run it.
I got errmsg :
ModuleNotFoundError: No module named 'pygtk'
In Pycharm I'm using python3 but I tried also on python2.
Without Pycharm in windows, I have the same problem.
Have someone solution to run scripts with gtk on Python3? It's even possible? I read that the gtk is no more supported, but I can't change a project.
Also, I tried to install pyGObject, but it's a problem with:
ModuleNotFoundError: No module named 'cairo'
The other posts found on SO doesn't work for me.
First lines in the code:
import pygtk, gtk
import numpy as np
import csv
....

ModuleNotFoundError: No module named 'speech_recognition'

I am using powershell and scoop, windows.
I already installed speech_recognition bucket but still showing the error.
Code:
import speech_recognition as sr
import time
import json
import requests
import thread
import subprocess
SPLUNK_URL = "https://localhost"
# Splunk http event collector token
hec_token = ""
The python interpreter shows a ModuleNotFoundError when it can't find the module being imported. For more information on how import works, click here.
Since you have installed latest python 3.7, and are working on a code snippet that was built 2 years ago, there is likely a case that the speech_recognition module might not be installed for your current python.
Before you try anything, execute
pip list
and see all the modules currently installed for your current python interpreter. If the speech_recognition module is not available in the list, then install it:
pip install SpeechRecognition
Also, if you are having multiple python versions installed on your system then make sure you use the pip installer of the python interpreter that you are using for your application. If you are using or like having multiple python versions, then I suggest you use a tool like pyenv.

ipython import modules fine but python import fails

there.
I'm not quite sure what I have done recently that cause the problem as mentioned in the title. I usually run the simple code in ipython, and run longer scripts use python command. However, just now it seems that python somescript.py doesn't work well if some modules are imported in the somescript.py file. For example, say it contains import matplotlib.pyplot as plt, when I run python somescript.py in the terminal, I will get an error message:
ImportError: no module named matplotlib. This is weird since when I run import matplotlib.pyplot as plt under ipython, it works fine, no error.
And I checked that the python version and path is different from ipython. ipython has several more paths that python, and the version is 2.7.11, while python is 2.7.10. So, what should I do to permanently resolve this issue? Add the other paths to python? How can I make sure that they import the same modules each time? Thanks a lot.

ImportError: No module named pyfftw

Im using Ubuntu 13.10 with python 2.7. When running code i get this error. I installed FFTW and not sure why I am getting this error. Here is my code:
import math
from gnuradio import gr
import numpy
import scipy.signal
import pyfftw
this is where I get the error. Any help would be great. Thanks
Check the sys.path in python. That tells you the module search path. If it is not in there, and not in the %PYTHONPATH% path (which should be in sys.path also) then it should not be able to find it. If you install a module, the interpreter still needs to know where to look for it, if it's not in the default search location.

Categories