I am trying to learn about the urllib module in python 3.6 in windows
i am able to install the module and run the code using the python application but when i run python from command at the code's location it errors and says the module isnt intalled. I have searched for all python.exe files on my PC and there is only 1.
c:\Python36\Scripts>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>>
>>> ^Z
c:\Python36\Scripts>
c:\Python36\Scripts>cd c:\Python36\Juggles\
c:\Python36\Juggles>python urllib.py
Traceback (most recent call last):
File "urllib.py", line 1, in <module>
import urllib.request
File "c:\Python36\Juggles\urllib.py", line 1, in <module>
import urllib.request
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a
package
c:\Python36\Juggles>
c:\Python36\Juggles>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python36\Juggles\urllib.py", line 1, in <module>
import urllib.request
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a
package
>>>
>>>
>>> import urllib.request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python36\Juggles\urllib.py", line 1, in <module>
import urllib.request
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a
package
>>>
>>> x = urllib.request.urlopen('https://www.google.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'urllib' is not defined
>>>
>>> print(x.read())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>>
Basically i installed the module using pip in the cmd > python pip.exe install..
Then i checked using import urllib and there were no errors
Then i went to the location of the code using cd and ran python urllib.py
and it says the module isnt installed.
Then i went into python again and it says the module isnt intalled.
But it was before... where did it go?
what am i doing wrong?
i also tried the -m option as suggested below but i get this error
c:\Python36\Scripts>python -m pip install urllib
Collecting urllib
Using cached urllib-1.21.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\butte\AppData\Local\Temp\pip-build-
ejdu38tm\urllib\setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\Juggles\AppData\Local\Temp\pip-build-ejdu38tm\urllib\
It is trying to do something in c:\users which isnt where the python.exe should be running from, which made me wonder if there was another version somewhere i cant seem to locate
I also just tried with elevated cmd from a new window (i always open cmd as admin) and get the same error below
C:\windows\system32>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> import urllib.request
c:\Python36\Juggles>python urllib.py
Traceback (most recent call last):
File "urllib.py", line 1, in <module>
import urllib.request
File "c:\Python36\Juggles\urllib.py", line 1, in <module>
import urllib.request
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a
package
Try python -m pip install package
There are two points to make in order to answer your question:
1. The urllib package you installed is a fake
The package you tried to install was a maliciously created python package that was designed to look like a real package (in this case urllib3). When installed, the package tried to send some basic information about the system on which you installed the package to a URL (you can see more details on this here). You can read more about this fake package at either of the following links:
https://app.threatconnect.com/auth/incident/incident.xhtml?incident=5256822&owner=Common%20Community (you can sign up for a free account to view this one)
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/index.html
Sending basic information about your systems to an unknown source isn't the worst thing you could do, but is certainly something you want to avoid when possible.
2. To properly install a package...
Specifically urllib:
To install urllib, you need to specify the version of urllib you would like to install. For example, pip install urllib3 or pip install urllib2.
Any package in general:
One helpful tool is the pip search <package-name> feature which lets you view the available packages that match a given name. This is not perfect, however, as it may list malicious libraries like the one you had installed. A good guideline is that you should follow the installation instructions in a package's documentation closely to avoid any unforeseen issues. This is just an unfortunate necessity of living in a world where people make pretend python packages.
Related
When I try (or another library tries) to import the 'numba' library I get the following error message: "DLL load failed while importing _typeconv: The specified module could not be found."
I have looked as deeply as I can in Google for similar occurrences and solutions. What I've found is only superficially similar and where solutions were even proposed they didn't work for me. At best I've come to the conclusion that I'm missing a particular DLL though I've no idea which one nor how to figure that out. Now I've got a Master's final project reliant on the usage of numba (indirectly, another third party library uses it) and I can't work around that.
I am using Python 3.8. It is the only Python installation on my Windows 10 machine (which is up-to-date as well). I am not using Anaconda nor am I willing to move to it at this point in time. I have installed numba on my system using "pip install numba" which gets the 0.49 version of numba.
After installing numba via pip, if I then start the Python CLI interface and attempt to import numba I get the following Traceback:
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numba
Traceback (most recent call last):
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\core\typeconv\typeconv.py", line 4, in <module>
from numba.core.typeconv import _typeconv
ImportError: DLL load failed while importing _typeconv: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\__init__.py", line 20, in <module>
from numba.misc.special import (
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\misc\special.py", line 3, in <module>
from numba.core.typing.typeof import typeof
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\core\typing\__init__.py", line 1, in <module>
from .context import BaseContext, Context
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\core\typing\context.py", line 11, in <module>
from numba.core.typeconv import Conversion, rules
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\core\typeconv\rules.py", line 2, in <module>
from .typeconv import TypeManager, TypeCastingRules
File "C:\Users\Luna\AppData\Local\Programs\Python\Python38\lib\site-packages\numba\core\typeconv\typeconv.py", line 17, in <module>
raise ImportError(msg % (url, reportme, str(e), sys.executable))
ImportError: Numba could not be imported.
If you are seeing this message and are undertaking Numba development work, you may need to re-run:
python setup.py build_ext --inplace
(Also, please check the development set up guide http://numba.pydata.org/numba-doc/latest/developer/contributing.html.)
If you are not working on Numba development:
Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new
If more help is needed please feel free to speak to the Numba core developers
directly at: https://gitter.im/numba/numba
Thanks in advance for your help in improving Numba!
The original error was: 'DLL load failed while importing _typeconv: The specified module could not be found.'
--------------------------------------------------------------------------------
If possible please include the following in your error report:
sys.executable: C:\Users\Luna\AppData\Local\Programs\Python\Python38\python.exe
Update
When rolling back to numba 0.48 this issue ends up disappearing.
I got the following numpy error. I have tried 1. But it did solve the problem. Would you please let me know how to fix the problem? Thanks.
$ python3
Python 3.8.0a3 (v3.8.0a3:9a448855b5, Mar 25 2019, 17:05:20)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.8 from "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: No module named 'numpy.core._multiarray_umath'
The problem is that I had Python 3.8.0a3 installed. I updated it to 3.8.1. Now the problem is solved.
I've been writing a reddit bot for a while now and recently moved it to a different system. There I've installed the same packages as on the previous system.
The bot is Python3 based so I install praw:
$ sudo pip3 install praw
[...]
Which went just fine as expected, but now when I import praw:
$ python3
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/praw/__init__.py", line 14, in <module>
from .reddit import Reddit # NOQA
File "/usr/local/lib/python3.4/dist-packages/praw/reddit.py", line 11, in <module>
from prawcore import (Authorizer, DeviceIDAuthorizer, ReadOnlyAuthorizer,
ImportError: No module named 'prawcore'
Even after manually adding the path to the module, I can't import praw.
>>> import sys
>>> sys.path.append('/usr/local/lib/python3.4/dist-packages/')
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/praw/__init__.py", line 14, in <module>
from .reddit import Reddit # NOQA
File "/usr/local/lib/python3.4/dist-packages/praw/reddit.py", line 11, in <module>
from prawcore import (Authorizer, DeviceIDAuthorizer, ReadOnlyAuthorizer,
ImportError: No module named 'prawcore'
With python(2), it seems to be working just fine.
How can I get my system to successfully import praw?
From reddit.com/r/redditdev:
pip3 install praw --upgrade --force-reinstall
did the job. Apparently something went wrong during the initial installation.
Here is the output of pip3 freeze:
Chases-MBP:/ chasehippen$ pip3 freeze
certifi==2018.1.18
chardet==3.0.4
flake8==3.5.0
get==0.0.39
idna==2.6
mccabe==0.6.1
pew==1.1.2
pipenv==9.0.3
post==0.0.26
public==0.0.65
pycodestyle==2.3.1
pyflakes==1.6.0
query-string==0.0.28
request==0.0.26
requests==2.18.4
six==1.11.0
urllib3==1.22
virtualenv==15.1.0
virtualenv-clone==0.2.6
And here's what happens when I try to import requests or urllib3:
Chases-MBP:/ chasehippen$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>> import urllib3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib3'
I reinstalled python 3 via homebrew twice, I don't understand why it won't let me import the modules?
If I run python import urllib2, that works fine, but only urllib3 fails.
Here are the outputs of where
Chases-MBP:~ chasehippen$ which pip3
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3
Chases-MBP:~ chasehippen$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
All of the resources I saw were saying I need to add the paths to .profile or .bashrc, but on mac, or at least mine, it's .bash_profile. I had to add "export PYTHONPATH="${PYTHONPATH}/Library/Frameworks/Python.framework/Versions/3.6/bin/":/usr/local/lib/python3.6/site-packages" to that file, and now importing works like a charm.
For anyone in the future reading this for an answer to using python3 on a mac, the file is ~/bash_profile , adding the line above in place of the default line that python 3 puts in there lets you use all of the modules that are installed in site-packages instead of bin
So the issue is that apparently Django uses the sqlite3 that is included with python, I have sqlite3 on my computer and it works fine on its own. I have tried many things to fix this and have not found a solution yet.
Please let me know how I can fix this issue so that I can use Django on my computer.
:~$ python
Python 3.5.2 (default, Nov 6 2016, 14:10:16)
[GCC 6.2.0 20161005] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
>>> exit()
I figured out that this error was caused by me changing my python path to 3.5 from the default of 2.7.