I don't know why request.compile() dosen't work - python

I don't have any files named re or requests in my source code directory.
The function 're.compile()' worked well a few days ago, but suddenly this error happens.
import requests as re
p = re.compile('[a-z]+')
m = p.search("python")
print(m)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_7864\2076162965.py in <module>
1 import requests as re
----> 2 p = re.compile('[a-z]+')
3 m = p.search("python")
4 print(m)
AttributeError: module 'requests' has no attribute 'compile'
So i deleted and reinstall requests library and checked how this code works, but same error happens.

Related

BUILD CHATBOTS WITH PYTHON- Discover Insights into Classic Texts

I keep getting this error code from my Jupyter Notebook and there is little to no explanation.
After inputting:
from nltk import pos_tag, RegexpParser
from tokenize_words import word_sentence_tokenize
from chunk_counters import np_chunk_counter, vp_chunk_counter
I get:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-14-a5041508c9f2> in <module>
1 from nltk import pos_tag, RegexpParser
----> 2 from tokenize_words import word_sentence_tokenize
3 from chunk_counters import np_chunk_counter, vp_chunk_counter
ModuleNotFoundError: No module named 'tokenize_words'
The full lesson allows the student to follow along with Jupyter. I don't know why but all it ever gives me is module not found error codes.

ModuleNotFoundError: No module named 'xagg.wrappers'

I am trying to import a package 'xagg' but it gives me the error described below. I managed to install 'xagg' but the following error popped up when I try to import it
Here is the command line
import xagg as xa
The error I got:
ModuleNotFoundError Traceback (most recent call last)
Input In [15], in <module>
----> 1 import xagg as xa
File ~\AppData\Roaming\Python\Python39\site-packages\xagg\__init__.py:5, in <module>
1 # Eventually restrict to just pixel_overlaps and aggregate; with
2 # everything else happening behind the scenes (and the exporting
3 # happening as methods to the classes that are exported from those
4 # two functions)
----> 5 from .wrappers import pixel_overlaps
6 from .aux import (normalize,fix_ds,get_bnds,subset_find)
7 from .core import aggregate
ModuleNotFoundError: No module named 'xagg.wrappers'
OS: Windows
pip install wrapper
I hope it work

neuropy problem having module not callable type error

I wrote this simple program after my installation in my anaconda3 jupyter:
from NeuroPy import NeuroPy
from time import sleep
neuropy = NeuroPy()
neuropy.start()
while True:
if neuropy.meditation > 70: # Access data through object
neuropy.stop()
sleep(0.2) # Don't eat the CPU cycles
But its giving this type error:
TypeError Traceback (most recent call
last) in ()
2 from time import sleep
3
----> 4 neuropy = NeuroPy()
5 neuropy.start()
6
TypeError: 'module' object is not callable
please help me out.
This is because both the function and class is named NeuroPy. I face similar problem with this.
Try neuropy = NeuroPy.NeuroPy()

NameError: name 'request' is not defined in python 3

I am trying to run the basic feature extraction code from the following site:
musicinformationretrieval.
When I try to run the following code line:
kick_filepaths, snare_filepaths = stanford_mir.download_samples(collection="drum_samples_train")
it shows the following error message:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-7c764e7836ee> in <module>()
----> 1 kick_filepaths, snare_filepaths = stanford_mir.download_samples(collection="drum_samples_train")
C:\Users\dell\Desktop\stanford-mir-gh-pages\stanford_mir.py in download_samples(collection, download)
89 for i in range(1, 11):
90 filename = '%s_%02d.wav' % (drum_type, i)
---> 91 urllib.urlretrieve('http://audio.musicinformationretrieval.com/drum_samples/%s' % filename,
92 filename=os.path.join(collection, filename))
93 kick_filepaths = [os.path.join(collection, 'kick_%02d.wav' % i) for i in range(1, 11)]
AttributeError: module 'urllib' has no attribute 'urlretrieve'
Please help me to solve this issue.
It seems you should use Python 2 insteed of 3. In instruction to stanford_mir there is line:
If you’re totally new, the simplest solution is to download and install Anaconda for Python 2 (2.7), not Python 3.
Also you can read why it is not working on Python 3 here.
UPD:
for using Python 3 you can try add code before using the lib:
import sys
if sys.version_info[0] >= 3:
from urllib.request import urlretrieve
else:
# Not Python 3 - today, it is most likely to be Python 2
# But note that this might need an update when Python 4
# might be around one day
from urllib import urlretrieve
UPD2:
urlretrieve import does not help)

I want to cause an ImportError

I'm trying to reach 100% testing coverage in a bit of code that I'm writing. The following block of code, however, is giving me trouble.
try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^localized_recurrence\.duration_field\.DurationField"])
except ImportError:
pass
The code above is part of my module under test. I need to create a test (without modifying the code above) which follows the ImportError branch.
How can I programmatically cause the ImportError to occur, while only writing code in my tests?
I'd try patching sys.modules and replacing south.modelsinspector with a mock module.
See the docs on Import statement for inspiration.
In [1]: from re import sub
In [2]: import sys
In [3]: sys.modules['re'] = {}
In [4]: from re import sub
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/kos/codility/frontend_v2/<ipython-input-4-6d4794835d43> in <module>()
----> 1 from re import sub
ImportError: cannot import name sub
You can do it in a narrow context by using mock.patch.dict (as a test decorator or context manager):
In [6]: with mock.patch.dict('sys.modules', {'re': {}}):
from re import sub
...:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-7479025ab931> in <module>()
1 with mock.patch.dict('sys.modules', {'re': {}}):
----> 2 from re import sub
3
ImportError: cannot import name sub
In [8]: from re import sub
In [9]:
You can change sys.path for the test. For example:
>>>import bs4
>>>
>>>import sys
>>>p=sys.path
>>>sys.path=['']
>>>import bs4
ImportError: No module named bs4
>>>sys.path=p
>>>import bs4
>>>
Just modify sys.path for that specific test on setUp() and later on tearDown() restore it.
Hope this helps!

Categories