ImportError: No module named _grabscreen - python

I am new to python and using this tutorial http://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117 to build a bot which plays games.
I copy-pasted the file and installed the libraries .When i tried running the file in the terminal on my mac i got this error :
Traceback (most recent call last):
File "bot.py", line 2, in <module>
import Image, ImageGrab, ImageOps
File "/Library/Python/2.7/site-packages/PIL/ImageGrab.py", line 34, in <module>
import _grabscreen
ImportError: No module named _grabscreen
Here is the complete code
import os, sys
import Image, ImageGrab, ImageOps
import time, random
from random import randrange
import win32api, win32con
from numpy import *

I think you should pay attention to the these words in the tutorial, 'Some of the code and libraries are Windows-specific. There may be Mac or Linux equivalents, but we won't be covering them in this tutorial.'.
And current version of ImageGrag only works for windows.

Related

Why isn't pyinstaller making a Tkinter window?

It's important to know that I am using pyinstaller to package python.
tkinter works perfectly fine when I package it with only:
import tkinter
root=tkinter.Tk()
root.mainloop()
but when I add some more of my code it shows the error:
Traceback (most recent call last):
File "exec", line 1, in <module>
import tkinter
File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: Module use of python39.dll conflicts with this version of Python.
These are all my imports:
import discord
import subprocess
from os import getcwd
import os
import pyautogui
from threading import *
import sys
I tried using only a tkinter window with no extra code and that worked!
But when I add the rest of my code it shows the error:
Traceback (most recent call last):
File "exec", line 1, in \<module\>
import tkinter
File "C:\\Program Files\\Python38\\lib\\tkinter\__init_\_.py", line 36, in \<module\>
import \_tkinter # If this fails your Python may not be configured for Tk
ImportError: Module use of python39.dll conflicts with this version of Python.

Raspberry Pi Dobot Magician connection using ctypes

I've wrote some code which connects with DobotMagician and moves its arm. It was firstly made for Windows but due to some project requirements i switched to Raspberry pi 4B (windows with python 3.10 pycharm to linux with python 3.9.2 and Thonny IDE). I'm struggling to rewrite the code for Linux. I'm keep getting following error:
Traceback (most recent call last):
File "/home/XYZ/Desktop/dobot_composite/dobot_composite_demov-master/main.py", line 26, in <module>
ctypes.cdll('/michalsiniarski/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library', mode=ctypes.RTLD_GLOBAL)
TypeError: 'LibraryLoader' object is not callable
Part of code producing an error:
import os
import sys
from serial.tools import list_ports
import pandas
import ctypes
from ctypes import *
from magician_library import DoBotArm as Dbt
from magician_library import DobotDllType as dType
from magician_library import *
import numpy as np
import logging
import time
import threading
import multiprocessing
import subprocess as sub
import keyboard
homey_max=160
homex_min, homex_max=180, 274
a_max=2*homey_max
b_max=homex_max-homex_min
h_max, h_min=50, -60
resolution=1
homeX, homeY, homeZ=225, 0, h_max
#os.add_cdll_directory('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library')
ctypes.cdll('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library', mode=ctypes.RTLD_GLOBAL)
Commented out part os.add.cdll...is almost 1:1 line rewritten from Windows version (difference is cdll and dll), which also produces an error:
Traceback (most recent call last):
File "/home/XYZ/Desktop/dobot_composite/dobot_composite_demov-master/main.py", line 25, in <module>
os.add_cdll_directory('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library')
AttributeError: module 'os' has no attribute 'add_cdll_directory'
Guide I followed:
https://github.com/SERLatBTH/StarterGuide-Dobot-Magician-with-Python#starting-out
I'm really new to python and I don't have more ideas how to make this work or even if this possible at all :c

Error when I import 'videosequence' in Python 3.9

import glob
import os
from contextlib import closing
from videosequence import VideoSequence
from PIL import Image
import face_recognition
import subprocess
from pytube import YouTube
When I run my project in a venv in Pycharm, this error message shows up
C:/Users/usr/PycharmProjects/project/main.py
Traceback (most recent call last):
File "C:\Users\usr\PycharmProjects\project\main.py", line 4, in <module>
from videosequence import VideoSequence
File "C:\Users\usr\PycharmProjects\project\venv\lib\site-packages\videosequence\__init__.py", line 9, in <module>
import gi
ModuleNotFoundError: No module named 'gi'
From the VideoSequence GitHub page:
The implementation is based on GStreamer and so de facto only works on a modern Unix-alike such as Linux or FreeBSD.
The PyGObject introspection libraries must be installed. (See below.)
You seem to be working on Windows (I do not know whether VideoSequence does in fact work on Windows), and, crucially, it is clear PyGObject is not installed.

How do I import NLTK to Python 3.7 on a Mac?

I have been trying to import the Natural Language Toolkit (NLTK) as per the code provided on https://www.nltk.org/install.html.
This code works on the terminal window on my mac (10.14), but refuses to import NLTK onto the interpreter provided with Python (IDLE).
I have already tried changing the directory by importing os module. (Changed the directory to the default Python library on macOS). This in turn yields errors from the NLTK scripts itself.
This is the code I ran
>>> import os
>>> os.getcwd()
>>> os.chdir('/Library/Python/2.7/site-packages')
>>> import nltk
I expected the nltk to successfully import after changing the directory.
However, it shows errors in the NLTK scripts itself (I'm assuming) which are as follows:
"Traceback (most recent call last):
File "", line 1, in
import nltk
File "/Library/Python/2.7/site-packages/nltk/init.py", line 99,
in
from nltk.internals import config_java
File "/Library/Python/2.7/site-packages/nltk/internals.py", line 28,
in
from six import string_types
ModuleNotFoundError: No module named 'six'"

ImportError: No module named 'PIL' in python 3.4

I have such code in the beginning of a file:
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
And it throws the error:
python3 main.pyTraceback (most recent call last):
File "main.py", line 1, in <module>
from PIL import Image
ImportError: No module named 'PIL'
According to many ad vices I should just replace import PIL with what I actually have. But is doesn't work as you can see.
It's on Ubuntu 14.04 and Python 3.4.0
According to this you should be able to do import Image instead of import PIL.

Categories

Resources