VSCode not recognising python modules - python

I'm writing a program in VSCode, for the mindstorms ev3dev software.
I need to import pyautogui to simulate Keypresses, but VSCode returns this:
Starting: brickrun --directory="/home/robot/vscode-hello-python-master" "/home/robot/vscode-hello-python-master/hello.py"
----------
Traceback (most recent call last):
File "/home/robot/vscode-hello-python-master/hello.py", line 7, in <module>
import pyautogui
ImportError: No module named 'pyautogui'
----------
Exited with error code 1.
Now, i've tried using a venv, i've tried multiple solutions online, and multiple different modules like numpy or pynput but none seemed to work. (Mysteriously the library I use to communicate with the brick, ev3dev2, works...). VSCode is able to see the module, and give me suggestions to functions like keyUp or keyDown, but when running it, it doesn't work.
Btw, i run the code by 'debugging', idk what that means, i followed some instructions online. The debugging is needed to run the code on the mindstorms brick, I think.
VSCode recognising module

Related

Python module, pyttsx3 not recognised in VS code or pycharm

I am trying to make a bot that responds to certain question asked like ‘what is the time’ . I am trying to use pyttsx3 module to make it work but this error is coming:
Traceback (most recent call last):
File "/Users/HarAd MAC/Desktop/Projects/Python_Work/bot.py", line 1, in <module>
import pyttsx
ImportError: No module named pyttsx3
I have download the module and checked it in VS code Terminal. It is also showing Requirement already satisfied. Can someone help me in this problem. Same error was shown when I was trying to run it in pycharm. These type of problems have also occurred when using modules that have to be download manually.
I am using MacBook Air big Sur and python 3.9.
Thanks.
I don't know for sure but I believe when your import the library you have to do import pyttsx3 while what you were doing is import pyttsx. Here's some more info on usage and how to import

ModuleNotFoundError: No module named 'pyvjoy'

I am currently trying to install a python module named "pyvjoy" (https://github.com/tidzo/pyvjoy) but I run into an error after importing
here's the error:
Traceback (most recent call last):
File "runner.py", line 5, in
import PlayHelper
File "C:\Users\Slay\Desktop\RLBot-master\PlayHelper.py", line 1, in
import pyvjoy
ModuleNotFoundError: No module named 'pyvjoy'
I have tried to install it via copying the library to C:\Python27\Lib\site-packages but no luck
1) You should be using a package manager instead of manually managing every package. Corollary: never use peoples code that isnt on pipy or conda, it means they havent gone through the effort to publish it and dont really expect anyone to use it.
2) You might like pygame or Tkinter for getting joystick input. Mature libraries that have been around for a while are almost always better then some dudes github project with 13 commits.

ImportError: No module named stdio, any way to start fresh with python?

I'm getting the error
Traceback (most recent call last):
File "ghs.py", line 1, in <module>
import stdio
ImportError: No module named stdio
When I try to run my script. I can run my script on other machines just fine. I have installed python using homebrew. And I've tried everything I can think of to get it to recognize my modules! I've uninstalled and reinstalled using brew. I've tried changing the path (though I don't fully understand this). I get no issues using brew doctor.
I've also tried using a python virtual environment but to no avail.
Any ideas on how to fix this issue or else 'start fresh' from a fresh version of python?
When you import a module, Python looks for it at the directory your code is, and the directory in which the built-in libraries are (C:\Users\pc\AppData\Local\Programs\Python\Python35-32\Lib in my case, I'm using Windows 10 and Python 3.5). If it can't find it, it raises ImportError.
I couldn't find a module named stdio in my computer. I also know some C++ and as far as I know, stdio is the library for inputs and outputs(prints). In python, there is no need to import such a library.
You can use try,except statement to test if your code works without importing the module like this.
try:
import stdio
except:
#rest of your code goes here
You will need to indent your whole code however this can be done easily with a text editor in which you can edit more than one line at a time.

`import pygame` shows no errors even when pygame is not installed

I've been installing, uninstalling, and reinstalling pygame because there's a program that I've been trying to run (that uses pygame). However whenever I've installed pygame, the program doesn't work.
Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\en\snake.py", line 28, in <module>
class Segment(pygame.sprite.Sprite):
AttributeError: 'module' object has no attribute 'sprite'
(Pygame is not installed when I receive this error supposedly)
What's really confusing me though is that when I type import pygame in normally in IDLE, I get no errors even when I just uninstalled it.
Windows 8 64 bit
Python 3.4.3
Pygame-1.9.2a0.win32-py3.4.msi (pygame file name)
Python is installed on C Drive (C:\Python34)
Whenever Pygame was installed, it was on the D drive
Have Python directory added to Path
Here's a screenshot of a video tutorial I was following, and it shows there are two installation paths. And here's mine, which only shows one path. I'm not sure if this is a big deal, but I just want to be sure.
Open your python interpreter and import pygame
Then you can print pygame to see exactly what is being loaded, should be something like: <module 'pygame' from '/Library/Python/2.7/site-packages/pygame/__init__.py'>
(repeat the above step until it fails importing pygame),
Close your prompt and install pygame. Try executing it again. Should the problem persist, you can edit some file in the game you are trying to run and add two lines: import sys and print sys.path and check the list of paths to make sure that there is not some other pygame installation somewhere bundled with the game that is being used instead of your installed pygame.
Modification of Josep Valls's answer:
You will need to change sys.path. This can be accomplished with the following code:
import sys
sys.path.append('''directory where pygame is''')
import pygame
The sys.path variable tell Python where to look for modules. By adding a path by append, you are telling Python to look for imported modules there. After that pointer is made, you can import pygame.

Error importing opencv, unable to import VideoCapturePlayer

I am trying to work with OpenCV in Python 2.7, however when I simply import cv2, I am getting this error:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "cv2.py", line 9, in <module>
from VideoCapturePlayer import *
ImportError: No module named VideoCapturePlayer
I figured that VideoCapturePlayer may be in pygame or pycam, but when I import both, no problems arise.
I have searched my folders and the web for VideoCapturePlayer. My folders do not contain it, and the internet provided a .py file, but I do not know where I should put it. Any help is greatly appreciated, thank you.
Edit: I guess I should include that I am on Windows 7 64-bit
The link you provided is for downloading the entire OpenCV project, including all the libraries and bindings for C++, Java, etc. etc. For the Python bindings, it's much easier to visit my favorite module site on the Internet, Christoph Gohlke's Python Extension Packages for Windows repository. Find the OpenCV section, pick AMD64 or Win32, pick py2.7 or py2.6, and wait a bit for the self-extracting archive to download. Run it, hit OK for all the prompts, and you should be all set. Fire up IDLE or run python from the command line, and running import cv2 should give you no response at all - indicating that everything got set up just fine.
Good luck!

Categories