Visual Studio Python PIP Times out looking for urllib2 - python

I am new to python on Visual Studio.
-----Here is my code-------------------------------
import urllib2
I need urllib2, but when I use PIP to get it, PIP times out.
What do I do? Do I setup a proxy? or can I manually import it somehow??

urllib2 is only available in Python 2, and is included as part of the standard library, which is why pip can't find it. For Python 3, you can use the various components of urllib, or for a much easier time of it, use the excellent requests module, which is available via pip.

Related

How do I edit a bug in a Python 3 API that I have installed?

I've installed the Podio API for Python 3 and found that it imports urlencode from urllib (from where you apparently would import it in Python 2), instead of urllib.parse (where it seems to be in Python 3), making me unable to do pretty much anything with the API. When I edit the code nothing happens and I'm assuming it's because I've already installed it, so how would I go about fixing that? I've looked around but didn't really find any clear instructions on how to do this.
The podio library for python available on pip doesn't seems to be up to date. The last version from github seem to fix your bug.
You should install it as it is recommanded on the project readme:
pip install -e git+https://github.com/podio/podio-py.git#egg=podio-py
(See this issue)
If it doesn't fix your bug, you should fix it on github and make a pull request. This way you will still be able to upgrade it if there is updates later.

Module requests Python

I am trying to use the requests module in a python script. I start by the import command and write the script however it is telling me that requests is not a module. Can anyone explain this to me? Is this not built in like "re" or do I have to import it in? I am new to python so any help would be great. Using Windows!
Thanks
Deirdre
No, requests is a 3rd party library. You can install it using pip.
pip install requests
And even if re is built-in, you have to import it in order to use it.

Import urllib.request, ImportError: No module named request

I am trying to import urllib.request for python 2.7.10 on PyCharm 4.5.4 on Window 10 but getting the error "ImportError: No module named request".
The urllib.request modules have been deprecated ..
just use
import urllib
And for your function if you were earlier writing say
urllib.request.urlretrieve
Now you just write
urllib.urlretrieve
I have also faced the same error and Googled to solve it.
urlib.request is for Python 3.0.
You may use the code below:
import urllib
urllib.urlopen(url)
You'll get this error if you try running a python 3 file with python 2.
Try to use this in Python3
try:
x = urllib.request.urlopen('https://www.google.com/search?q=test')
print(x.read())
except Exception as e:
print(str(e))
It may happen sometimes, usually in the Linux environment. You have both 2.x and 3.x versions of python installed.
So, in that case, if you are using the command python "file.py"
then by default, it will python 2.x will run the file.
So, use the command python3 "file.py"
I was facing this issue. Maybe it can resolve someone's issue.
Try this:
#!/usr/bin/env python3
import urllib
response = urllib.urlopen("http://google.com")
html = response.read()
print(html)
The first line "#!/usr/bin/env python3" is important, as it let python know that this is Python 3 file, not 2.
Hope everything works.
Use > Path\easy_install.exe requests if you have a windows machine, where easy_install can be found in your Python*\Scripts folder, if it was installed. (Note Path\easy_install.exe is an example, mine is C:\Python32\Scripts\easy_install.exe)
If you don't have easy install and are running on a windows machine, you can get it here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#distribute
If you manually want to add a library to a windows machine, you can download the compressed library, uncompress it, and then place it into the Lib folder of your python path.
OR
You need to install pip first and then install django-request using pip
pip install django-request
also install,
python setup.py install
then import
from urllib.request import urlopen
Helpful Tips:to chech this

Importing requests module in python using netbeans

I'm using netbeans to write a simple python program which I need the requests module for, I've downloaded requests through terminal and it all seems to be fine there but netbeans can't seem to find it.
This is the error that it's throwing up:
import requests
ImportError: No module named requests
I've tried installing the requests library directly into the python folder but the folder won't let me paste anything into it.
There do seem to be answers on the netbeans forums but their server is down so won't let me on their website to my annoyance!
EDIT
I've tried to run python setup.py install as per other answers on the website but had no luck.
EDIT
have tried completely uninstalling python and requests to make sure it wasn't an installation error but still no luck.
This clearly looks like an error of installation of the request module to some other place than where your netbeans expects when running the code.
In your console run
which python
Check if this gives the same path as the one set in your netbeans. You can set your path by adding new platform using Tools > Python Platforms > New:
I would suggest that you learn bit more about sandboxed environments such as virtualenv. This article shows how you can use a virtualenv to install packages and use the same virtualenv for netbeans so that whatever packages you install in the virtualenv will be available in the netbeans for you to use. For this case, it could be requests.
In the end I gave up with requests, as I was using requests to get json data from an API I decided just to go back to the drawing board and start over rather than attempt to fix something that I couldn't work out. I am now using the urllib import and whilst this may not be the most efficient way it works which is the most important thing.

How to add a library in python

I am trying to authenticate jawbone api in python. In the code there is a line:
import requests
How can I add this. I have very little knowledge on python. Just manipulating the code. Can any one please help? The library is already present in python 3.3
This is only for the users using python33 and in windows platform,,,,
download Requests packages from any site.
Copy the folder Requests from the downloaded package and place it on C://python33/LIB/ folder....
now you are able to import Requests package to your program

Categories

Resources