I wanted to install urllib2 package from PyPI but it is not available.
It seems that it has been updated to urllib3, but is there any way to download urllib2 ?
import urllib2
Is that what you want?
If you find any library under http://docs.python.org/ you can always import without installing it.
Update 1:
If you need the source code...
The official Cpython code: http://hg.python.org/cpython/file/3b5fdb5bc597/Lib/urllib
Note The urllib2 module has been split across several modules in
Python 3 named urllib.request and urllib.error. The 2to3 tool will
automatically adapt imports when converting your sources to Python 3.
or try this? http://code.reddit.com/docs/urllib2-pysrc.html
I can't guarantee the integrity for the second alternative link.
Related
I read this in addition to MANY other things: Importing requests module does not work
I am using VSCode and python 3.8.
I am able to import it seems any library except "requests"
Given the ages of the previous posts I hope to know what a good current next step could be, please and thank you
import math
import asynchat
import signal
import importlib
import requests <-----Will NOT import
response = requests.get("http://api.open-notify.org/astros.json" [api.open-notify.org])
print(response.text)
print(response)
I think your requests is not well installed. Make sure it's installed with the python you are using with.
Try pip3 install requests.
So, I have a mac on High Sierra and I am trying to import and use an api. This is api is a python3 api and uses bs4, and specifically is using lxml within bs4 in order to parse a webpage.
However, I am having an issue getting bs4 to recognize that I have lxml installed on my machine. I have installed both of them using pip, and both appear to have installed correctly. I can write a program with ‘import bs4’ and ‘import lxml’ at the top and it compiles and runs perfectly fine. However, no matter what I do I always get the following error when I run a program using this api.
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
On top of this, when I run the following code
import lxml
import bs4
print(bs4.builder.builder_registry.builders)
the output is
[<class 'bs4.builder._htmlparser.HTMLParserTreeBuilder'>]
With no lxml listed.
I have tried everything I have found on the various stack overflow threads related to this. I have uninstalled and reinstalled both lxml and bs4 through various methods(pip, easy install, manually installing, homebrew). I've manually linked lxml from brew. And other things ive probably forgotten. However I cant get it to work.
Anyone have any ideas/has anyone gone through this before. Its possible I'm completely missing something small or stupid, since I've never messed with bs4 before, but I dont know.
I'm not exactly sure what's the cause, but I had a similar case with a Flask app I'm working on. I worked around it by importing bs4 locally in the function where I needed it.
One symptom I had was when I logged bs4.builder.builder_registry.builders at the top of my module, the logs ended up showing two entries: first with the proper builders and then with only HTML.
So I installed BS4 with PIP, but when I do
from bs4 import beautifulsoup4
I get this
ImportError: No module named html.entities
I've done all the research I can into this as it seems to be a fairly rare problem, and the only thing I could find is to only have one version of python installed, yet I need both python two and three installed so that wouldn't work.
So I was wondering if there's a better way to fix this error, I have read http://www.crummy.com/software/BeautifulSoup/bs4/doc/#problems-after-installation by the way, there appeared to be nothing in there that would help my situation.
Thanks for your help! And sorry for my formatting
I'm writing a sublime text 2 plugin that uses a module SEAPI.py which in itself imports the requests module.
Since sublime text 2 uses it's own embedded python interpreter, it doesn't see the requests module installed in my ubuntu machine (I get the following error: ImportError: No module named requests).
Best solution I could find so far was to copy the 'requests' module (the whole directory of files) from /usr/lib/python2.7/dist-packages/requests into my plugin directory in the sublime text packages dir.
But after that, it says that it can't find the 'urllib3' module.
Is there a better way to import the requests module so that I won't have to copy all the files into my plugin directory ?
The current code I'm using is as follows:
MyPlugin.py
import sublime
import sublime_plugin
import SEAPI
...
SEAPI.py
import requests
try:
import simplejson as json
except:
import json
from time import time, sleep
...
Edit:
The selected answer is correct and fixes my main question, but a different problem exists with using the current version of 'Requests' with the embedded sublime text 2 interpreter. ST2's python is missing various modules which exist in regular 2.7 python (such as 'fileio').
I've solved it with using the 'Requests' module from here:
https://github.com/bgreenlee/sublime-github
And I had to edit the 'urllib3/response.py' file to this:
try:
from cStringIO import StringIO as BytesIO
except ImportError:
pass # _fileio doesn't seem to exist in ST's python in Linux, but we don't need it
You need to bundle full requests distribution with your Python package and then modify Python's sys.path (where it looks for modules) to point to a folder containing requests folder.
Download Requests library from a PyPi and extract it manually under your plugin folder
Before importing requests in your plugin, append the corrcet folder to sys.path to point a folder where it can found requests import
The (untested) code should look like something like this:
import sys
import os
# request-dists is the folder in our plugin
sys.path.append(os.path.join(os.path.dirname(__file__), "requests-dist"))
import requests
This also assumes that requests setup.py does not do any hacks when you install the module using easy_install or pip.
You also could import requests zip directly as Python supports importing from ZIP files, assuming requests is distributed in compatible way. Example (advanced):
https://github.com/miohtama/ztanesh/blob/master/zsh-scripts/python-lib/zipimporter.py
More about sys.path trick (2004)
http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html
Mikko's answer is good, but I may have found a slightly easier way:
import MyAwesomePlugin.requests
"MyAwesomePlugin" being the name of your plugin, of course.
I want o use Python-docx library to process word files. A docx.py references lxml, as i assume from
from lxml import etree
When i start the script, i get error:
No module named lxml
Is this a standard library? Why is not it referenced properly then? IronPython 2.7 RC1.
You need to install lxml which is not part of the stdlib. I don't know if it will work with IronPython though.
Update: Seems like it might be non-trivial to get lxml working with IronPython. See this question:
How to get lxml working under IronPython?