Error while trying to run script with atom - python

I'm trying to run script like below in atom (or in pycharm)
import numpy as np
def bar(num_elems):
restrained_dofs = 0
m = np.array([[2,1], [1,2]]) / (6. * num_elems)
k = np.array([[1,-1],[-1,1]]) * num_elems
M = np.zeros((num_elems+1,num_elems+1))
K = np.zeros((num_elems+1,num_elems+1))
for i in range(num_elems):
M_temp = np.zeros((num_elems+1,num_elems+1))
K_temp = np.zeros((num_elems+1,num_elems+1))
M_temp[i:i+2,i:i+2] = m
K_temp[i:i+2,i:i+2] = k
M += M_temp
K += K_temp
for dof in range(restrained_dofs):
for i in [0,1]:
M = np.delete(M, dof, axis=i)
K = np.delete(K, dof, axis=i)
bar(1)
and I recive following terminal output
Traceback (most recent call last):
File "D:/Programowanie/Python/bar_elem.py", line 1, in <module>
import numpy as np
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\_internal.py", line 12, in <module>
from numpy.compat import basestring, unicode
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\compat\__init__.py", line 14, in <module>
from . import py3k
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\compat\py3k.py", line 14, in <module>
from pathlib import Path
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\pathlib.py", line 13, in <module>
from urllib.parse import quote_from_bytes as urlquote_from_bytes
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\urllib\parse.py", line 597, in <module>
_asciire = re.compile('([\x00-\x7f]+)')
AttributeError: module 're' has no attribute 'compile'
But the same script is working correctly while using Spyder3 or in Terminal.
I'm running script wit Script packacge in Atom, but other packages gives the same result.
Python 3.7.1,
Numpy 1.15.4

The problem was that the script was placed in a folder named Python, after moving it to another location everything works fine

Related

'NoneType' object has no attribute 'eglGetCurrentContext'

I am having a problem with python and pyopengl
I am just importing the modules, and getting errors, I checked and pip did install opengl and everything.
Here is my code
# ulWindow
import ulMath as ulm
import OpenGL.GL as gl
import OpenGL.GlE as gle
import glfw
def init() ->int|str:
if (not glfw.init()):
return "GLFW Failed to initialize"
return 0
And the error im getting:
Traceback (most recent call last):
File "src/ulWindow.py", line 3, in <module>
import OpenGL.GL as gl
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/GL/__init__.py", line 4, in <module>
from OpenGL.GL.VERSION.GL_1_1 import *
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_1_1.py", line 14, in <module>
from OpenGL.raw.GL.VERSION.GL_1_1 import *
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/raw/GL/VERSION/GL_1_1.py", line 7, in <module>
from OpenGL.raw.GL import _errors
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/raw/GL/_errors.py", line 4, in <module>
_error_checker = _ErrorChecker( _p, _p.GL.glGetError )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/error.py", line 183, in __init__
self._isValid = platform.CurrentContextIsValid
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 356, in CurrentContextIsValid
return self.GetCurrentContext
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/egl.py", line 106, in GetCurrentContext
return self.EGL.eglGetCurrentContext
AttributeError: 'NoneType' object has no attribute 'eglGetCurrentContext'
I have absolutely no clue what is going on, can someone help me out?

Problems with Weasyprint: ModuleNotFoundError

I would like to display the text from an image and then have the coordinates determined for each word in the text. For this I use the following code:
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
import json
import math
import PIL
from PIL import ImageDraw
import matplotlib.pyplot as plt
model = ocr_predictor (det_arch='db_resnet50', reco_arch='crnn_vgg16_bn',pretrained=True)
bildpfad = "C:/Users/b2/Documents/Analysetext_1.png"
bild = DocumentFile.from_images (bildpfad)
ergebnis = model (bild)
output = ergebnis.export ()
with open ("C:/Users/b2/Documents/docTR_OCR_output.json", "w") as f:
f.write (json.dumps (output, indent=1))
f.close ()
ergebnis.show (bild)
# Geometrische Koordinaten
for object_1 in output ['pages'] [0] ["blocks"]:
for object_2 in object_1 ["lines"]:
for object_3 in object_2 ["words"]:
print ("{}: {}".format (object_3 ["geometry"], object_3 ["value"]))
# Output like [x_min, x_max, y_min, y_max]
# Geographische Koordinaten
def convert_coordinates (geometry, page_dim):
len_x = page_dim[1]
len_y = page_dim[0]
(x_min, y_min) = geometry[0]
(x_max, y_max) = geometry[1]
x_min = math.floor(x_min * len_x)
x_max = math.ceil(x_max * len_x)
y_min = math.floor(y_min * len_y)
y_max = math.ceil(y_max * len_y)
return [x_min, x_max, y_min, y_max]
def get_coordinates (output):
page_dim = output ['pages'][0]["dimensions"]
text_coordinates = []
for object_1 in output ['pages'][0]["blocks"]:
for object_2 in object_1 ["lines"]:
for object_3 in object_2 ["words"]:
converted_coordinates = convert_coordinates (object_3 ["geometry"], page_dim)
print ("{}: {}".format (converted_coordinates, object_3 ["values"]))
text_coordinates.append (converted_coordinates)
return text_coordinates
graphical_coordinates = get_coordinates (output)
print (graphical_coordinates)
# Plot graphische Koordinaten
def draw_bounds(bild, bound):
draw = ImageDraw.Draw(bild)
for b in bound:
p0, p1, p2, p3 = [b[0],b[2]], [b[1],b[2]], \
[b[1],b[3]], [b[0],b[3]]
draw.line([*p0,*p1,*p2,*p3,*p0], fill='blue', width=2)
return bild
bild = PIL.Image.open(bildpfad)
result_image = draw_bounds(bild, graphical_coordinates)
plt.figure(figsize=(15,15))
plt.imshow(result_image)
At the beginning I had the following error:
OSError: cannot load library 'gobject-2.0-0': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
I was then able to fix this error and now the following is displayed:
ModuleNotFoundError: No module named 'weasyprint.text.ffi'; 'weasyprint.text' is not a package
The whole output is:
Traceback (most recent call last):
File "c:/Users/b2/Documents/Übungen/Distanzberechnungen/Textdetection_Übung_3.py", line 3, in <module>
from doctr.io import DocumentFile
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\__init__.py", line 1, in <module>
from . import datasets, io, models, transforms, utils
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\datasets\__init__.py", line 3, in <module>
from .generator import *
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\datasets\generator\__init__.py", line 4, in <module>
from .tensorflow import *
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\datasets\generator\tensorflow.py", line 8, in <module>
from .base import _CharacterGenerator, _WordGenerator
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\datasets\generator\base.py", line 11, in <module>
from doctr.io.image import tensor_from_pil
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\io\__init__.py", line 2, in <module>
from .html import *
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\doctr\io\html.py", line 8, in <module>
from weasyprint import HTML
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\weasyprint\__init__.py", line 315, in <module>
from .css import preprocess_stylesheet # noqa isort:skip
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\weasyprint\css\__init__.py", line 25, in <module>
from . import computed_values, counters, media_queries
File "C:\Users\b2\anaconda3\envs\Python_3_6\lib\site-packages\weasyprint\css\computed_values.py", line 9, in <module>
from ..text.ffi import ffi, pango, units_to_double
ModuleNotFoundError: No module named 'weasyprint.text.ffi'; 'weasyprint.text' is not a package
I hope you can help me to fix this error. Thank you in advance

Error in .exe of python script having Barcode from Reportlab.graphics

I have a python script for generating barcodes (code128) which works fine in IDE.
But when converted into exe, it encounters below error:
Traceback (most recent call last):
File "amazonbarcode-dubai.py", line 6, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "reportlab\graphics\barcode\__init__.py", line 76, in <module>
File "reportlab\graphics\barcode\__init__.py", line 42, in _reset
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "reportlab\graphics\barcode\widgets.py", line 166, in <module>
File "reportlab\graphics\barcode\widgets.py", line 95, in _BCW
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'reportlab.graphics.barcode.code128'
I tried import code128 from reportlab.graphics.barcode that also works fine with IDE but fails in exe.
Below is my python script:
import os
import pandas as pd
from reportlab.pdfgen import canvas
from reportlab.graphics import barcode
from reportlab.lib.units import mm
cwd = os.getcwd()
df1 = pd.read_csv(cwd+'\\exportedTable.csv')
df2 = pd.read_excel(cwd+'\\AMAZON BARCODE.xlsx',dtype=str)
df3 = pd.merge(df1,df2,left_on='ASIN',right_on='amazonasin',how='left')
df_missing = df3[df3.item.isnull()]
if df_missing.size>0:
print(df_missing.to_string())
print(df_missing.columns)
df_missing = df_missing[['Model number','UPC/EAN/ISBN','ASIN']]
df_missing.to_excel(cwd+'\\amazonmissingbarcode.xlsx',index=False)
df3 = df3.sort_values('model').reset_index()
df3['ctn'] = df3.index+1
df3 = df3[['ctn','model','barcode','amazonasin','Package tracking ID','PO number']]
df3.columns = ['ctn','model','ean','asin','accn','pono']
print(df3.to_string())
f = df3.pono.unique()[0]
cb = canvas.Canvas(f+'-big.pdf')
cb.setPageSize((100*mm,75*mm))
barcode = barcode.code128.Code128
for i,row in df3.iterrows():
barcode(row['asin'],barHeight=20*mm,barWidth=0.5*mm).drawOn(cb,9*mm,53*mm)
cb.setFont("Helvetica",10)
cb.drawCentredString(54*mm,50*mm,'ASIN : ' + row['asin'])
barcode(row['pono'],barHeight=15*mm,barWidth=0.5*mm).drawOn(cb,15*mm,32*mm)
cb.setFont("Helvetica",10)
cb.drawCentredString(54*mm,29*mm,'PO NO. : '+row['pono'])
barcode(row['accn'],barHeight=15*mm,barWidth=0.4*mm).drawOn(cb,7*mm,12*mm)
cb.setFont("Helvetica",10)
cb.drawCentredString(54*mm,9*mm,row['accn'])
cb.setFont("Helvetica-Bold",12)
cb.drawString(5*mm,4*mm,'MODEL: '+row['model'])
cb.drawRightString(95*mm,4*mm,'CTN NO.: '+str(row['ctn']))
cb.showPage()
cb.save()

Import errors in Numba

The code :::: Does anyone can help me with this ?
from numba import vectorize
#vectorize(['int64(int64, int64)'], target='cuda')
def add_ufunc(x, y):
return x + y
print('a+b:\n', add_ufunc(a, b))
print()
print('b_col + c:\n', add_ufunc(b_col, c))
The error ::::
Traceback (most recent call last): File "array.py", line 1, in
from numba import vectorize File "/usr/lib/python3.7/site-packages/numba/init.py", line 11, in
from . import config, errors, _runtests as runtests, types File "/usr/lib/python3.7/site-packages/numba/config.py", line 9, in
import multiprocessing File "/usr/lib/python3.7/multiprocessing/init.py", line 16, in
from . import context File "/usr/lib/python3.7/multiprocessing/context.py", line 6, in
from . import reduction File "/usr/lib/python3.7/multiprocessing/reduction.py", line 136, in
import array File "/home/felipe/cuda/array.py", line 1, in
from numba import vectorize ImportError: cannot import name 'vectorize' from 'numba'
(/usr/lib/python3.7/site-packages/numba/init.py)

python Multiple linear regression find pvalue

I need to find the pvalue. for a multiLinearRegression. However, I can not use import statsmodels.formula.api as sm. It throws a error for me :( is there a way to find the pvalue without using statsmodels? this is what I have so far.
import numpy
from scipy.stats import pearsonr
data = numpy.genfromtxt("2-2.4.txt",delimiter=",")
x = data[:,6]
x2 = data[:,7]
x3 = data[:,8]
x4 = data[:,9]
y = data[:,-1]
r, p = pearsonr(x,x2,x3,x4, y) # how do I find the pvalue when working with multiple variables
error I get with statsmodel when importing
File "C:\Python27\lib\site-packages\statsmodels\formula\__init__.py", line 4, in <module>
from formulatools import handle_formula_data
File "C:\Python27\lib\site-packages\statsmodels\formula\formulatools.py", line 1, in <module>
import statsmodels.tools.data as data_util
File "C:\Python27\lib\site-packages\statsmodels\tools\__init__.py", line 1, in <module>
from tools import add_constant, categorical
File "C:\Python27\lib\site-packages\statsmodels\tools\tools.py", line 14, in <module>
from pandas import DataFrame
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 39, in <module>
from pandas.core.api import *
File "C:\Python27\lib\site-packages\pandas\core\api.py", line 10, in <module>
from pandas.core.groupby import Grouper
File "C:\Python27\lib\site-packages\pandas\core\groupby.py", line 18, in <module>
from pandas.core.frame import DataFrame
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 39, in <module>
from pandas.core.series import Series
File "C:\Python27\lib\site-packages\pandas\core\series.py", line 2995, in <module>
import pandas.tools.plotting as _gfx # noqa
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 134, in <module>
if _mpl_ge_1_5_0():
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 129, in _mpl_ge_1_5_0
return (matplotlib.__version__ >= LooseVersion('1.5') or
File "C:\Python27\lib\distutils\version.py", line 296, in __cmp__
return cmp(self.version, other.version)
AttributeError: 'unicode' object has no attribute 'version'

Categories

Resources