ImportError: No module named url - python-3.5

when i run the the given code in prepare_dataset.py whose code is below as
from urllib.request
import urlopen
import json as simplejson
def main():
# Download and prepare datasets
list_generator = video_list_generator.Generator("playlists.json", youtube_api_client.Client("AIzaSyD_UC-FpXbJeWzPfscLz9RhqSjKwj33q6A"))
video_list = list_generator.get_video_list("piano")
downloader = youtube_video_downloader.Downloader()
downloader.download_from_list(video_list)
if __name__ == '__main__':
main()
as python prepare_dataset.py in command-line then i get these errors
Traceback (most recent call last):
File "prepare_dataset.py", line 1, in <module>
from urllib.request import urlopen
ImportError: No module named request
How can i get to run the above file any idea guys?

Related

Python can properly be executed in IDEA, but when executing the executable file, following error appears: ModuleNotFoundError: No module named 'PIL'

I wrote a small Python script which takes all .jpeg img-files from a given "./Input" folder, creates a thumbnail from these images and saves them in a "./Output" file. It works perfectly fine when executed in an IDEA (In my case PyCharm), but when I created the executable with pyinstaller and tried to execute it, the following error appeared:
Traceback (most recent call last):
File "image_resizer.py", line 3, in <module>
ModuleNotFoundError: No module named 'PIL'
[84693] Failed to execute script 'image_resizer' due to unhandled exception: No module named 'PIL'
[84693] Traceback:
Traceback (most recent call last):
File "image_resizer.py", line 3, in <module>
ModuleNotFoundError: No module named 'PIL'
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Here is my code:
import shutil
from PIL import Image
import glob, os
import time
output_directory = "./Output"
def photo_picker():
pictures = []
try:
for filename in glob.iglob("./Input/*.jpg"):
pictures.append(filename)
except FileNotFoundError:
print("could not execute")
return pictures
def create_output_folder():
if os.path.exists(output_directory):
shutil.rmtree(output_directory)
try:
os.mkdir(path=output_directory, mode=777)
except FileExistsError:
print("Could not execute")
def crop_image(img, new_name):
size = (2000, 2000)
with Image.open(img) as im:
im.thumbnail(size)
print(im.info)
img_name = f"{new_name}"
im.save(output_directory + "/" + img_name, "JPEG")
def main():
photos = photo_picker()
create_output_folder()
time.sleep(2)
for f in photos:
img_name_splitted = f.split("/")
img_name = img_name_splitted[len(img_name_splitted) - 1]
print(img_name)
crop_image(f, img_name)
return 0
if __name__ == "__main__":
main()
I installed the module Pillow, uninstalled it ,tried to install PIL (which didn't work). But as I mentioned before, when executing it in an IDEA it works.

Why do i get this "Urllib" problems?

ok can someone explain why this code dosen't work
import urllib.request, urllib.parse, urllib.error
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
counts = dict()
for line in fhand:
words = line.decode().split()
for word in words:
counts[word] = counts.get(word, 0) + 1
print(counts)
i get this traceback
Traceback (most recent call last):
File "C:\Users\boris\OneDrive\Desktop\python\urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
File "C:\Users\boris\OneDrive\Desktop\python\urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package

ModuleNotFoundError: No module named in PyCharm

I was able to run the project using the command line, but from last 1 day I am not able to run the command from the command line However using GUI the project is running fine...
C:\Users\tester\PycharmProjects\Selenium\SampleProjects\POMProjectDemo\Tests>py
thon login.py
Traceback (most recent call last):
File "login.py", line 6, in <module>
from SampleProjects.POMProjectDemo.Pages.loginPage import LoginPage
ModuleNotFoundError: No module named 'SampleProjects'
C:\Users\tester\PycharmProjects\Selenium\SampleProjects\POMProjectDemo\Tests>py
thon -m unittest login.py
E
======================================================================
ERROR: login (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: login
Traceback (most recent call last):
File "C:\Users\tester\AppData\Local\Programs\Python\Python37-32\lib\unittest\
loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "C:\Users\tester\PycharmProjects\Selenium\SampleProjects\POMProjectDemo\
Tests\login.py", line 6, in <module>
from SampleProjects.POMProjectDemo.Pages.loginPage import LoginPage
ModuleNotFoundError: No module named 'SampleProjects'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
[![Tests/login.py
import time
from selenium import webdriver
import unittest
from selenium.common.exceptions import NoSuchElementException
from SampleProjects.POMProjectDemo.Pages.loginPage import LoginPage
from SampleProjects.POMProjectDemo.Pages.homePage import HomePage
import HtmlTestRunner
from SampleProjects.POMProjectDemo.Utility.XLUtil import getData
class LoginTest(unittest.TestCase):
#classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome(executable_path='F:/Selenium/chromedriver.exe')
cls.driver.implicitly_wait(10)
cls.driver.maximize_window()
def test_login_valid(self):
path = 'c:/Users/mahmood/PycharmProjects/Selenium_automaton/Login.xlsx'
# global path
driver = self.driver
row = getData.getRowCount(path,'Sheet1')
for r in range(2,row+1):
driver.get("https://opensource-demo.orangehrmlive.com/")
userN = getData.readData(path,'Sheet1',r,1)
passW = getData.readData(path,'Sheet1',r,2)
Same code was running fine, what changes I have done not able to debug it.

Can't pickle <class 'pywintypes.datetime'>: attribute lookup datetime on pywintypes failed

I am using python 3.5 (32bit), win10-64bit, OpenOPC, and I have downloaded pywin32 build 64bit. I have run the following python code:
import OpenOPC
import time
opc=OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation.1')
tags =['Random.Int4','Random.Real4']
while True:
try:
value = opc.read(tags,group='Group0',update=1)
print (value)
except OpenOPC.TimeoutError:
print ("TimeoutError occured")
time.sleep(5)
but I always get this error message:
Traceback (most recent call last): File "C:\Program Files
(x86)\Python35-32\lib\multiprocessing\queues.py", line 241, in _feed
obj = ForkingPickler.dumps(obj) File "C:\Program Files (x86)\Python35-32\lib\multiprocessing\reduction.py", line 50, in dumps
cls(buf, protocol).dump(obj)
_pickle.PicklingError: Can't pickle : attribute lookup datetime on pywintypes failed.
I have found a solution:
import OpenOPC
import time
import pywintypes
pywintypes.datetime = pywintypes.TimeType
opc=OpenOPC.client()
opc.servers()
opc.connect('Matrikon.OPC.Simulation.1')
tags =['Random.Int1','Random.Real4','Random.Int2','Random.Real8']
while True:
try:
value = opc.read(tags,group='Group0',update=1)
print (value)
except OpenOPC.TimeoutError:
print ("TimeoutError occured")
time.sleep(1)

Python 3.4 : cStringIO vs. StringIO

QUESTION
I am returning an ImportError: No module named 'cStringIO'. Unfortunately cStringIO doesn't exist anymore and I need to use StringIO as a replacement. How can I do this?
import edgar
import ftplib
from io import StringIO
ftp = ftplib.FTP(edgar.FTP_ADDR)
ftp.login()
try:
edgar.download_all(ftp, "/tmp")
except Exception as e:
print(e)
finally:
ftp.close()
OUTPUT
Traceback (most recent call last):
File "/usr/local/lib/ana/lib/python3.4/site- packages/edgar/downloader.py", line 5, in <module>
from cStringIO import StringIO
ImportError: No module named 'cStringIO'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/aranjohn/PycharmProjects/edgar/secEd.py", line 1, in <module>
import edgar
File "/usr/local/lib/ana/lib/python3.4/site- packages/edgar/__init__.py", line 1, in <module>
from .downloader import FTP_ADDR, file_list, download, download_all
File "/usr/local/lib/ana/lib/python3.4/site- packages/edgar/downloader.py", line 7, in <module>
from StringIO import StringIO
ImportError: No module named 'StringIO'
Process finished with exit code 1
StringIO no longer exists in 3.x. Use either io.StringIO for text or io.BytesIO for bytes.

Resources