ImportError: No module named pyscreenshot - python

I have created I python program which makes 100 screenshots, and saves them on a folder called img inside the OS folder Documents. It worked perfectly fine in my Linux Ubuntu, it did the 100 screenshots and saved them in the directory I wanted. Now, I created a new Linux user in the same Virtual Machine, and I ran the same python script.
It gives me this error: ImportError: No module named pyscreenshot
I have tried many times. It works in my other user, although in the new one it keeps giving me error. Is there any reason for this?
Thanks. The code is below:
import os
import pyscreenshot as ImageGrab
def photos(num):
for n in range(num):
s = str(n)
a = "../Documents/img/s" + s + ".png"
# grab fullscreen
im = ImageGrab.grab()
# save image file
im.save(a)
return True
Quick note: I am calling the function photos() from another file using import screenshot (the file is called 'screenshot.py')

try to install pyscreenshot for your user
pip install pyscreenshot

Just in case the answers provided above don't work, try using
sudo -H pip install pyscreenshot

Related

Why can't I import cv2 from anywhere else than install dir?

I'm using anaconda with spyder on Win 10. I installed opencv by pip-install opencv-python.
If I do
import cv2
in the default directory (C:\ProgramData\Anaconda3), it will work.
However, if I do the same command anywhere else I'll have an error :
import cv2
Traceback (most recent call last):
File "<ipython-input-3-c8ec22b3e787>", line 1, in <module>
import cv2
ImportError: DLL load failed: Le module spécifié est introuvable.
If I want to run a script which needs cv2, I have to go in C:\ProgramData\Anaconda3 , then import cv2 and finally run my script in whatever directory I want.
I don't have this problem with other modules, like pygame or pillow.
This may be because the IDE may contain many Interpreter and the cv2 library is not installed for the python Interpreter which is set for the system, try to install the cv2 with command prompt using pip install opencv-python. then it may work for you from any location.
Ok, thanks to Abhishek-Saini.
Following this video where pip directory is added to PATH, I added C:\opencv\build\x64\vc15\bin to path. And, it works ! (for now, then)

How to import pyHook on Spyder (Python 3.7)

I'm trying to use pyHook to get my image to change when I click on it with the mouse. But when I run my code, I get an error.
My Code:
from __future__ import print_function
from PIL import Image
import pyHook
import pythoncom
im = Image.open("H:/---------/Images/nature.jpg")
print(im.format, im.size, im.mode)
im.show()
def OnMouseEvent(event):
im1 = Image.open("H:/----------/Images/nature.jpg").convert("L")
im1.show()
hm = pyHook.HookManager()
hm.MouseLeft = OnMouseEvent
hm.HookMouse()
pythoncom.PumpMessages()
This is the error:
ModuleNotFoundError: No module named 'pyHook'
Screenshot:
Open up your terminal and type:
pip3 install pyHook
It is case-sensitive. So type it properly.
After that, your python environment will have pyHook installed as a module and you will be able to successfully import in your code
EDIT:
Try the following steps since you find the above did not work.
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
Check your computer system and download the correct .whl file.
Open up your computer's terminal and navigate to your .whl file location. Example: cd C:\Users\ycx\Desktop
Type in: pip3 install pyHook‑1.5.1‑cp37‑cp37m‑win_amd64.whl This part should be your exact filename which you downloaded off the website.

Python HTML and script not working after "import pytube"

So, Im trying to do a conversor, and I had a successful work at it, but, when I was trying to execute the python script by the localhost, it simply didn't work.(btw, Im using XAMPP as the local server)
Here is a code that functions until before the "import pytube":
print("Content-type: text/html\n")
import sys
import os
print("<html><head><title>HelloCGI</title></head")
print("<body><h1><i>Hello</h1></body></html>")
import pytube
url = "https://www.youtube.com/watch?v=eH4F1Tdb040"
yt = pytube.YouTube(url)
yt.streams.last().download(r'C:\xampp\htdocs\converter_My\songs')
os.chdir(r'C:\xampp\htdocs\converter_My\songs')
os.system('ren *.webm *.mp3')
Ok, for some stupid reason, I put the import pytube after the print's, and then, it went...
#!C:\xampp\htdocs\converter_My\Python\Python37-32\python.exe
print("Content-type: text/html\n")
import sys
import os
print("<html><head><title>HelloCGI</title></head")
print("<body><h1><i>Hello</h1></body></html>")
import pytube
url = "https://www.youtube.com/watch?v=44Mz-kwonWk"
yt = pytube.YouTube(url)
yt.streams.last().download(r'C:\xampp\htdocs\converter_My\songs')
os.chdir(r'C:\xampp\htdocs\converter_My\songs')
os.system('ren *.webm *.mp3')
Maybe I made you waste a little bit of your time, but thank you...:)
I always need to do it:
from pytube import*
import pytube
I hope it works :)
PS: You don't add error message so it is litle hard to repair
EDIT: Make sure then using pip you have console with ADMIN privilages
I also got the same problem but make sure while you are installing them use
1.pip for python2
2.pip3 for python3
so with python3 use
pip3 install PyTube
make sure to take care of t

Can't save to wav from python, can't import SpeechLib from comtypes.gen, what next?

First the setup: Windows 8.1 64bit, Python 3.4 32bit.
I wanted to run the code here. So I installed comtypes
pip install comtypes
I then tried to run the code, i got
ImportError: cannot import name 'SpeechLib'
Then tried this code here to try and generate the needed SpeechLib module.
I am however still getting the same error, what should I try next?
Running these lines made it work:
from comtypes.client import CreateObject
engine = CreateObject("SAPI.SpVoice")
stream = CreateObject("SAPI.SpFileStream")
Output was:
# Generating comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4
# Generating comtypes.gen.SpeechLib
After this I got no import error anymore, as expected.

Import pillow without installing

I am working on a Python project that requires PIL to show images. However, the computers that I am working on often do not allow me to install things, and have a very bare bones python setup. For this reason, most of the modules that I need I simply place in the same directory as my python files.
I tried doing the same with PIL. I downloaded the pillow source, and copied the PIL folder into my project. I was then able to run "import PIL" with no problems. However, when I then tried to run "from PIL import Image" I get the error: "The _Imaging C module is not installed". From other searches I think that installing Pillow properly would fix this problem, however I would like PIL to be more portable, and not require an instillation.
Any ideas would be great. Thanks in advance.
One solution is bundle PIL in with the script in .egg form. Then, you can import PIL directly from the .egg instead of having to install it:
How to create Python egg file
The basic process is as follows:
How to create egg:
Edit PIL's setup.py to include from setuptools import setup instead of normal setup import
Run python setup.py bdist_egg
Egg will be inside of dist/
How to import egg:
Copy .egg file to script's directory and import desired modules:
import os
import sys
DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(DIR, "./path/to/PIL.egg"))
#You can now import from PIL normally:
from PIL import Image

Categories

Resources