'ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package
I have the following code and i tried all i could find on stackoverflow but nothing worked. Here is the code:
import urllib.request, urllib.parse, urllib.error
fhand = urllib.request.urlopen('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)
And the error: ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package
Solution 1:[1]
do you have urllib installed? if not try to install it like this : pip install urllib3
Solution 2:[2]
I found the problem. I already had a file that was named urllib.py and that is why the error. Now that i deleted it everything works fine! Hope this answer will help everyone in need.
Solution 3:[3]
This exact same issue happened to me. After trying and trying, I just ended up rewriting the code and saving the file into a new folder by itself and it ran without any problems.
Hope this helps!
Solution 4:[4]
In your example 6x6 matrix, the first three columns are linearly dependent; the second column and third column are both just scalar multiples of the first column:
>> a=<your example>;
>> a(:,1:3)./a(:,[1 1 1])
ans =
1.000000000000000e+00 1.135821455052853e-01 -1.319363866841049e-01
1.000000000000000e+00 1.135821455052859e-01 -1.319363866841050e-01
1.000000000000000e+00 1.135821455052855e-01 -1.319363866841045e-01
1.000000000000000e+00 1.135821455052838e-01 -1.319363866841038e-01
1.000000000000000e+00 1.135821455052868e-01 -1.319363866841046e-01
1.000000000000000e+00 1.135821455052856e-01 -1.319363866841046e-01
The inverse in this case doesn't really make sense; it's not just an issue with scaling among the different 3x3 submatrices.
Various possibilities:
- There's a bug in whatever generated the example and the correct matrix is reasonably conditioned (though perhaps badly scaled). Applying a simple diagonal scaling
sc = diag(1 ./ sqrt(diag(a)))on both sides will usually fix the scaling if that's the only problem. - The very slight difference in the last digits of the printing above is actually significant and not just rounding noise from the computation of
a. I.e., they're actual signal and are what would really determine the result you want. Then you've just run out of precision in the normal representation. You'll have to do some sort of reformulation to make these visible. - The column dependence is telling you something about the problem, and it's really a lower dimension than the 6x6. Taking into account the symmetry and looking at
a1 = a(3:6, 3:6)(dropping the two dependent columns plus the corresponding rows), the result is badly scaled butsc * a1 * sc(withscas above) is reasonable with a condition number of about2e6.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gorbachev |
| Solution 2 | Dharman |
| Solution 3 | Edu |
| Solution 4 | bg2b |
