I installed cython in lubuntu and trying complie 'hello World' program using terminal command
python3 setup.py build_ext
but gcc returns compilation error.
Here is my setup.py code
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("cython.pyx")
)
and cython.pyx code
print("hello World")
got it by using terminal command
python3 setup.py build_ext --inplace
and changed setup.py to
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("hello", ["cython.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
Related
I have a selenium python automation test, it works fine, now I want to generate Html and JSON reports and have screenshots in the report using pytest. I am new to automation and python so I am not much aware of how its done.
following is my code
test_screenshot.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pytest_html
from selenium.common.exceptions import InvalidSessionIdException
def test_Openurl(setup):
driver = setup["driver"]
url = setup["url"]
try:
driver.get(url)
except Exception as e:
print(e.message)
assert driver.current_url == URL
driver.save_screenshot("ss.png")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.save_screenshot("ss1.png")
driver.close()
conftest.py
import pytest
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
def pytest_addoption(parser):
parser.addoption("--url", action="store", default="https://google.com/")
#pytest.fixture()
def setup(pytestconfig):
s = Service("C:/Users/Yash/Downloads/chromedriver_win32/chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.maximize_window()
yield {"driver":driver, "url": pytestconfig.getoption("url")}
I ran this using
pytest test_screenshot.py --url "https://www.netflix.com/in/"
Test case is passed. How do I generate HTML and JSON report?
I tried this
pytest -v -s --json-report --json-report-indent=4 --json-report-file=report/report.json --html=report/report.html test_screenshot.py
but got this error
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --json-report --json-report-indent=4 --json-report-file=report/report.json
inifile: None
You need to install these two libraries : https://pypi.org/project/pytest-json-report/ & https://pypi.org/project/pytest-html/
I am getting the error TesseractError: (2, 'Usage: pytesseract [-l lang] input_file'). Using ! sudo apt install but still getting the error in colab.
Its a JPG I am trying to read.
-----------------------------code -------------------------------------
! apt install tesseract-ocr
! apt install libtesseract-dev
! sudo apt install tesseract-ocr
! pip install Pillow
! pip install pytesseract
import pytesseract
import shutil
import os
import cv2
import random
from google.colab import files
from io import BytesIO
from PIL import Image,ImageFilter
!pip install pdf2image
!apt-get install -y poppler-utils
from pdf2image import convert_from_path
#from google.colab import drive
!sudo apt install tesseract-ocr
!pip install pytesseract
!pip install tesseract
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
image_path_in_colab = 'Pillow block drawing.jpg'
img = cv2.imread('Pillow block drawing.jpg')
custom_config = r'-l eng --psm 6'
pytesseract.image_to_string(img, config=custom_config)
extractedInformation = pytesseract.image_to_string(Image.open(image_path_in_colab))
print(extractedInformation)
install:
!sudo apt install tesseract-ocr
Change:
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
to:
pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
you need to set the tesseract location as env variable . Like this
pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
The following line is wrong
pytesseract.pytesseract.tesseract_cmd =
r'/usr/local/bin/pytesseract'
I am working on a Spark Application and I want to create a rest API in Django, below is my code
from django.shortcuts import render
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from django.http import JsonResponse
from django.core import serializers
from django.conf import settings
import json
from pyspark import SparkContext, SparkConf, SQLContext
sc = SparkContext()
sql = SQLContext(sc)
df = Sql.read.format("jdbc").options(
url = "jdbc:mysql://127.0.0.1:3306/demo",
driver = "com.mysql.cj.jdbc.Driver",
dbtable = "tablename",
user = "xyz",
password = "abc"
).load()
totalrecords = df.count()
# Create your views here.
#api_view(["GET"])
def Demo(self):
try:
a = str(totalrecords)
return JsonResponse(a,safe=False)
except ValueError as e:
return Response(e.args[0],status.HTTP_400_BAD_REQUEST)
I want to know how will I run this code, as I have directly tried "python manage.py runserver" which is not working, so how to run this spark and django with django api and spark-submit with all required spark jar file?
To run this code you have to use spark submit only,
spark-submit --jars mysql.jar manage.py runserver 0.0.0.0:8000
or
spark-submit manage.py runserver
i try to install my website on a webserver which is in CentOS 7 with Django 2.0.6 and Python 3.6.
I installed : mysql-connector = 2.1.6,
mysql-connector-python = 8.0.11,
MySQL-python = 1.2.5,
mysqlclient = 1.3.12,
PyMySQL = 0.8.1
And when i run this command :
python3.6 manage.py migrate
I have this error :
File "MYPYTHONPATH/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 1.2.5
But in the base.py file :
try:
import MySQLdb as Database
except ImportError as err:
raise ImproperlyConfigured(
'Error loading MySQLdb module.\n'
'Did you install mysqlclient?'
) from err
from MySQLdb.constants import CLIENT, FIELD_TYPE # isort:skip
from MySQLdb.converters import conversions # isort:skip
# Some of these import MySQLdb, so import them after checking if it's installed.
from .client import DatabaseClient # isort:skip
from .creation import DatabaseCreation # isort:skip
from .features import DatabaseFeatures # isort:skip
from .introspection import DatabaseIntrospection # isort:skip
from .operations import DatabaseOperations # isort:skip
from .schema import DatabaseSchemaEditor # isort:skip
from .validation import DatabaseValidation # isort:skip
version = Database.version_info
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
I dont understand what can i do for resolving this kind of problem !
I hope someone can help me on =)
Okay, i solved it with the answer of this thread.
No module named MySQLdb
pip install PyMySQL
and then add this two lines to your Project/Project/init.py
import pymysql
pymysql.install_as_MySQLdb()
Works on WIN and python 3.3+
My directory structure
kents-air:Cython-Test kent$ tree
.
├── main.py
├── setup.py
└── test
├── test.c
└── test.pyx
1 directory, 4 files
test.pyx
from libc.stdio cimport FILE
cdef class RandomTest:
cdef File * reader
cdef int number
def __init__(self, number):
self.number = number
def print_random(self):
print(self.number)
main.py
from .test import RandomTest
tester = RandomTest(5)
tester.print_random()
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize(["test/*.pyx"]),
)
Output
pythkents-air:Cython-Test kent$ python3 setup.py build_ext
Compiling test/test.pyx because it changed.
[1/1] Cythonizing test/test.pyx
Error compiling Cython file:
------------------------------------------------------------
...
from libc.stdio cimport FILE
cdef class RandomTest:
cdef File * reader
^
------------------------------------------------------------
test/test.pyx:4:9: 'File' is not a type identifier
Traceback (most recent call last):
File "setup.py", line 5, in <module>
ext_modules = cythonize(["test/*.pyx"]),
File "/usr/local/lib/python3.5/site-packages/Cython/Build/Dependencies.py", line 912, in cythonize
cythonize_one(*args)
File "/usr/local/lib/python3.5/site-packages/Cython/Build/Dependencies.py", line 1034, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: test/test.pyx
Version Info
kents-air:Cython-Test kent$ python3
Python 3.5.1 (default, Apr 18 2016, 11:46:32)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Cython==0.24
Links I have already checked:
Declaring FILE pointers in Cython
Pass file handle to cython function