How do I fix WinError 126 for Pyenchant? - python

I am relatively new to Python. I already know what most things are and do so now I am trying to work on as many projects as I can to get familiar with Python coding.
But here I've run into a speed bump. I'm trying to create something that takes in letters from a user to generate words ranging from 3 letters to the length of the word.
My code is okay, I think, but when I run it I get a WinError 126 and I'm not trying to import any dll files. I reckon it has something to do with Pyenchant.
Please, may someone help me??
CODE & ERROR:
from itertools import permutations
import enchant
d = enchant.Dict("en_UK")
WORDS = set()
LETTERS = input("ENTER LETTERS: ")
PERMS = [i.upper() for i in LETTERS]
for n in range(2, len(LETTERS)):
for x in list(permutations(PERMS, n)):
ANAGRAMS = "".join(x)
if d.check(ANAGRAMS):
WORDS.add(ANAGRAMS)
print(WORDS)
_________________________________________________________
Traceback (most recent call last):
File "C:\Users\JAVA MANU\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\WordScapes cheat tool v2.py", line 2, in <module>
import enchant
File "C:\Users\JAVA MANU\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\enchant\__init__.py", line 81, in <module>
from enchant import _enchant as _e
File "C:\Users\JAVA MANU\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\enchant\_enchant.py", line 161, in <module>
e = ctypes.cdll.LoadLibrary(enchant_lib_path)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 442, in LoadLibrary
return self._dlltype(name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

Related

Problem with opening an Excel file with pandas

I encounter this problem trying to open an excel file with the following code :
#===================================
#different import
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd
section_copper = 50.11*8.04#[mm2]
section_alu = 50.18*5.07 #[mm2]
section_composite = 53.24*4.49 #[mm2]
section_steel = 50.35*10.23 #[mm2]
length = 400 #[mm]
data_steel = pd.read_excel(r"C:\Users\Alex\Downloads\MAPR2481-Lab1.xlsx",sheet_name=0)
data_aluminium = pd.read_excel(r"C:\Users\Alex\Downloads\MAPR2481-Lab1.xlsx",sheet_name=1)
data_copper = pd.read_excel(r"C:\Users\Alex\Downloads\MAPR2481-Lab1.xlsx",sheet_name=2)
data_composite = pd.read_excel(r"C:\Users\Alex\Downloads\MAPR2481-Lab1.xlsx",sheet_name=3)
The following message can be found in the console :
runfile('C:/Users/Alex/.spyder-py3/lab 1.py', wdir='C:/Users/Alex/.spyder-py3')
Traceback (most recent call last):
File "<ipython-input-16-9c6aa501dded>", line 1, in <module>
runfile('C:/Users/Alex/.spyder-py3/lab 1.py', wdir='C:/Users/Alex/.spyder-py3')
File "C:\Users\Alex\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\Alex\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Alex/.spyder-py3/lab 1.py", line 3, in <module>
import numpy as np
File "C:\Users\Alex\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py", line 143, in <module>
from . import _distributor_init
File "C:\Users\Alex\AppData\Roaming\Python\Python37\site-packages\numpy\_distributor_init.py", line 26, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Users\Alex\Anaconda3\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
I would be very grateful if someone could help me !
Please check this answer here
You are using Anaconda i assume.
You have installed the wrong version of python, like you have a 32bit system and u installed 64bit version of python.
Solution: re-install Anaconda as administrator (but first delete the first and all associated files with it).
hope this solves your issue.

Problem with importing bitcoin library in python

Today I've run into problems trying to use the python-bitcoinlib in a small python program. It worked perfectly a few days ago but today the library seems to be broken (see console output below).
I'm in a Mac with OS X 11.0.1 (yes, I upgraded today, but I would be surprised if that's the cause of the problem).
I've tried several times installing and uninstalling the library and even python, but nothing seems to happen.
Thanks in advance.
>>> from bitcoin.rpc import RawProxy
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
from bitcoin.rpc import RawProxy
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bitcoin/rpc.py", line 48, in <module>
from bitcoin.wallet import CBitcoinAddress, CBitcoinSecret
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bitcoin/wallet.py", line 33, in <module>
import bitcoin.core.key
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bitcoin/core/key.py", line 34, in <module>
_ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(libeay32, 6): image not found
My solution is not using RawProxy.
Impor this instead:
from bitcoinrpc.authproxy import AuthServiceProxy
And connect to bitcoin core with this sentence or equivalent:
p = AuthServiceProxy("http://%s:%s#127.0.0.1:8332"%(rpcuser, rpcpassword))

Fixing subprocess.py file Error: File not found? [duplicate]

This question already has answers here:
What exactly is current working directory?
(5 answers)
Closed 27 days ago.
I am using a python package from Gray Arrow's Dejavu. I have installed all the required dependencies and other packages necessary to run my code. When running the following code:
import warnings
import json
warnings.filterwarnings("ignore")
from dejavu import Dejavu
from dejavu.recognize import FileRecognizer
with open('dejavu.cnf') as f:
config = json.load(f)
djv = Dejavu(config)
djv.fingerprint_file('mp3/Sean-Fournier--Falling-For-You.mp3')
song = djv.recognize(FileRecognizer, 'mp3/Sean-Fournier--Falling-For-
You.mp3')
print("from file recognized: {}\n".format(song))
I receive the following errors:
Traceback (most recent call last):
File "testing.py", line 13, in <module>
djv.fingerprint_file('mp3/Sean-Fournier--Falling-For-You.mp3')
File "D:\dejavu-master\dejavu\__init__.py", line 109, in
fingerprint_file song_name=song_name
File "D:\dejavu-master\dejavu\__init__.py", line 182, in
_fingerprint_worker channels, Fs, file_hash = decoder.read(filename,
limit)
File "D:\dejavu-master\dejavu\decoder.py", line 51, in read
audiofile = AudioSegment.from_file(filename)
File "C:\Program Files\Python37\lib\site-
packages\pydub\audio_segment.py", line 665, in from_file info =
mediainfo_json(orig_file)
File "C:\Program Files\Python37\lib\site-packages\pydub\utils.py",
line 263, in mediainfo_json res = Popen(command,
stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\Program Files\Python37\lib\subprocess.py", line 775, in
__init__ restore_signals, start_new_session)
File "C:\Program Files\Python37\lib\subprocess.py", line 1178, in
_execute_child startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file
specified
I have done complete re-installations of python 3.7 and all of the packages and dependencies to attempt correction of this problem.
I do not understand what file cannot be found and have done research in hopes to find an answer to this issue. I truly appreciate any help and knowledge that can be shared with me on this topic.
Try and place "Sean-Fournier--Falling-For-You.mp3" file in the exact directory you have your script, I don't think the folder reference to the mp3 folder is being handled correctly :)
djv.fingerprint_file('mp3/Sean-Fournier--Falling-For-You.mp3')
song = djv.recognize(FileRecognizer, 'mp3/Sean-Fournier--Falling-For-
You.mp3')

Issue with python version 2.7.3 importing maxrepeat module

I am trying to import maxrepeat module in python 2.7.3 and couldn’t get much information in google can some one please help.
What is the module that helps maxrepeat module to work ?
I am able to import maxrepeat module using “from _sre import maxrepeat” but still fails while runnninv automation .
MAXREPEAT is used internally by the re module as an upper limit for the minimum, maximum, or exact number of repetitions that can be specified in a pattern. For example:
>>> import re
>>> re.compile(r'a{100}') # exactly 100 "a"s
<_sre.SRE_Pattern object at 0x7fa68be10780>
>>> re.compile(r'a{100, 200}') # between 100 and 200 "a"s
Equalling or exceeding MAXREPEAT in a repetition value causes an exception to be raised by the regular expression parser in module sre_parse:
>>> from sre_constants import MAXREPEAT
>>> MAXREPEAT
4294967295L
>>> re.compile(r'a{{{}}}'.format(MAXREPEAT-1))
<_sre.SRE_Pattern object at 0x7f0ec959f660>
>>> re.compile(r'a{{{}}}'.format(MAXREPEAT))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/re.py", line 194, in compile
return _compile(pattern, flags)
File "/usr/lib64/python2.7/re.py", line 249, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib64/python2.7/sre_compile.py", line 572, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib64/python2.7/sre_parse.py", line 716, in parse
p = _parse_sub(source, pattern, 0)
File "/usr/lib64/python2.7/sre_parse.py", line 324, in _parse_sub
itemsappend(_parse(source, state))
File "/usr/lib64/python2.7/sre_parse.py", line 518, in _parse
raise OverflowError("the repetition number is too large")
OverflowError: the repetition number is too large
There should not be any reason to care about MAXREPEAT with normal use of the re module. If you need to handle errors then use the exception:
try:
re.compile(r'a{{{}}}'.format(MAXREPEAT))
except OverflowError as exc:
print 'Failed to compile pattern: {}'.format(exc.message)

PyStemmer: ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed

I'm using the Python package Bag of Words, bow.py (https://github.com/dmiro/bagofwords/blob/master/bow.py).
Basically I'm running the command:
dc = bow.DefaultDocument()
dc.read_text("paragraph string here")
I get the following trace:
Traceback (most recent call last):
File "bag_of_words.py", line 93, in <module>
if __name__ == "__main__": main()
File "bag_of_words.py", line 27, in main
bag_of_words_classifier_test("item", "category_1", "category_2")
File "bag_of_words.py", line 73, in bag_of_words_classifier_test
dc.read_text("paragraph string here")
File "C:\Users\User Name\Anaconda3\lib\site-packages\bow.py", line 339, in read_text
self._read(None, text)
File "C:\Users\User Name\Anaconda3\lib\site-packages\bow.py", line 326, in _read
words = self.tokenizer(text)
File "C:\Users\User Name\Anaconda3\lib\site-packages\bow.py", line 306, in tokenizer
words = self.after_tokenizer(WordFilters, words)
File "C:\Users\User Name\Anaconda3\lib\site-packages\bow.py", line 517, in after_tokenizer
words = wordfilters.stemming(self.lang, self.stemming, words)
File "C:\Users\User Name\Anaconda3\lib\site-packages\bow.py", line 250, in stemming
import Stemmer as stemmer
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
I thought it might be an issue with PyStemmer, so I tried forcing a pip3 reinstall/upgrade but got the same error. Any thoughts?
Okay, so this doesn't really solve the problem, but it is a work-around:
If you open bow.py you can replace line 250 with import snowballstemmer as stemmer (instead of import Stemmer as stemmer) and then replace line 252 with stemmer = stemmer.stemmer(lang) (instead of stemmer = stemmer.Stemmer(lang)). The equivalent methods just require a change from uppercase to lowercase.

Categories