Everyone's code online refers to sudo apt-get #whatever# but windows doesn't have that feature. I heard of something called Powershell but I opened it and have no idea what it is.
I just want to get a simple environment going and lxml so I could scrape from websites.
Go to the regular command prompt and try pip install lxml. If that doesn't work, remove and reinstall python. You'll get a list of check marks during installation, make sure you check pip and try pip install lxml again afterwards.
pip stands for pip installs packages, and it can install some useful python packages for you.
Try downloading the lxml package from here, then, on the command prompt, type in:
pip install path/to/lxml_package_file
For example, after downloading lxml‑3.5.0‑cp35‑none‑win_amd64.whl since I have Python 3.5 on a 64-bit Windows box, I type in the following commands:
cd path/to/lxml_file
pip install lxml‑3.5.0‑cp35‑none‑win_amd64.whl
Then it should install fine.
Other packages may be used instead:
import xml.etree.cElementTree as etree
import xml.etree.ElementTree as etree
import cElementTree as etree
import elementtree.ElementTree as etree
The lxml.etree Tutorial
Related
I am new to Linux. On my Oracle Virtual Machine, I have several versions of Python installed.
Now I would like to install the lxml library in my Python 3.7, but I don't know how to specify the terminal to do so. The command pip install lxml that was recommanded to me returns : Requirement already satisfied : lxml in <my path to Python 3.8>
What I understand is that by default, it installs lxml in Python 3.8. How can I change that into Python 3.7 please ?
How can I change that into Python 3.7 please ?
According to python docs regarding working with multiple versions of python installed in parallel you might
On Linux, Mac OS X, and other POSIX systems, use the versioned Python
commands in combination with the -m switch to run the appropriate copy
of pip
so in your case
python3.7 -m pip install lxml
You must know how to start the Python3.7 version. If you start it with full_path_to_python37, then you should use the following to install lxml in it:
full_path_to_python37 -m pip install lxml
I am trying to install BeautifulSoup4 and having trouble with pip. I have installed pip but when I go to run pip install BeautifulSoup nothing happens. Just a new line comes up on CMD
e.g.
C:\Python27\Scripts>pip install BeautifulSoup
C:\Python27\Scripts>
Anyone have any ideas? This is Windows 7 btw. May well be something obvious I'm missing as I'm really new to Python.
Thanks in advance.
Edit:
I should also add that when I then try from bs4 import BeautifulSoup I get the following error:-
ImportError: No module named bs4
Try these troubleshooting steps
1.Be sure you've followed all of these instructions carefully.
2.Check your path environmental variables to make sure you can run python from the command line.
3.Check your python DIRECTORY for the SCRIPTS folder. Look there to see if pip is there. I'm not 100 percent for sure but I think you must have pip here for it to be able to run from the command line.
By the way:
4.If you have python 3.4 or later, pip may already be installed.
if all else fails....
5.download this and run this in an admin cmd window:
python get-pip.py
6.try running the update commands if nothing else has worked.
pip install -U setuptools
7.er....switch to easy_install
I'm having difficulty properly installing lxml for Python on Mac. I have followed the instructions here, which after installation indicates that the installation is successful (however, there are some warnings. The full log of the install and warnings can be found here)
After running the install, I am trying to run Test.py in the lxml install directory to ensure that it's working correctly. I am immediately prompted with the error:
ImportError" cannot import name etree.
This error results from the line from lxml import etree.
I can't seem to figure out why it's failing here after a seemingly successful install. Please forgive my ignorance, as I don't typically program in Python and certainly never on a MAC (forced to do so at the moment).
For reference:
Python Version: 2.7.2
Mac OS X 10.8.2
Thanks in advance for all the help.
Sounds like you have another lxml in your path. Make sure you are referencing the right one, it should look something like this:
>>> import lxml
>>> lxml
<module 'lxml' from '/path/to/lib/python2.7/site-packages/lxml/__init__.pyc'>
I had the same problem as you.
My problem was that I named one of my Python files lxml.py.
You should always check if your Python file's name conflicts with a module.
Microsoft Server
Spyder IDE
Python 3.7 and Python 3.9
Documenting this as I couldn't find the solution ANYWHERE on Google/StackOverflow etc.
Regarding SharePlum, SharePoint Integration, issues with
import from lxml import etree
ImportError: cannot import name etree
I had the same issue while trying to use SharePlum with Spyder IDE.
I tried installing, uninstalling, and installing versions of the below with no success
pip install shareplum
pip install lxml
I had Python 3.9 installed and Spyder IDE (which I didn't know, also installs it's own version of Python 3.7 - as at 13 May 2021 Spyder version) .. [even though the Spyder IDE is set up to search all python package inventories (e.g. ../Python39/Lib/Site-Packages) for packages] there seems to be a Spyder issue with Python pulling packages from other paths.
Solution, I have uninstalled all Python and Spyder IDE installations.
I then ONLY installed Spyder IDE (which nests a python install within it's PATH. I then went into the PATH ".../Spyder/Python" where you can find all the familiar Python.exe and other familiar Python files. I had to use this install of Python to install Pip, and then I could "pip install -r requirements.txt" - which installs etree lxml and other goodies such as SharePlum etc.
This seemed to do the trick!
I had the same problem using PyCharm IDE v2021.2 with Python 3.8
What worked for me was in PyCharm,
go to Preferences -> Python Interpreter,
uninstall the lxml package,
close & restart PyCharm,
install the lxml package
Dunno why it worked, but it did.
I have a working setup of lxml.etree working on my windows desktop.
Since I wanted to move this to my server, instead of installing lxml in sitepackages, I wanted to install it inside the modules directly, so this lxml version is specific to this applicaion/site.
I copied my lxml directory directly under modules on the linux server, and I got this error :
No module named etree
So it seems it understood there is an lxml, package but couldn't see etree inside it.
Any ideas ?
Also, I couldn't find exactly where I can download the binaries for ubuntu 9.10 on the site : http://lxml.de/installation.html#installation
You can't just copy the Windows version over to a Linux server; lxml uses C extensions which need to be compiled for the target platform.
The etree module is such a compiled extension, on Linux that'd be etree.so, while on Windows it would be a etree.dll file instead, for example.
For Ubuntu, look for python-lxml, or install the dependencies libxml2-dev, libxslt1-dev and python-dev, plus python-pip, then use sudo pip install lxml to install lxml on your server.
I want to install pyquery on windows. But i cant run setup.py install on the command line. Do you have any hint?
I guess you don't have lxml or setuptools installed
setuptools
http://pypi.python.org/pypi/setuptools/0.6c11
lxml
http://pypi.python.org/pypi/lxml/2.2.2
Install them first and then try again, I just tried that, its working properly here.
I could not install lxml on windows with either pip or easy_install. Complained "Unable to find vcvarsall.bat"
Tried installing Cygwin and MinGW but that was taking way too long
found out from raidsan's answer about unofficial precompiled windows binaries
http://www.lfd.uci.edu/~gohlke/pythonlibs/
installed and works fine now
SIMPLE WORKING SOLUTION:
I download the tar file here pyquery-1.2.13.tar.gz (https://pypi.python.org/pypi/pyquery#downloads)
I extracted them a folder pyquery-1.2.13 then i pasted myscript.py to this folder pyquery-1.2.13 in my script i have these lines at the very top to include pyquery module and it works!
import pyquery (this file is in pyquery-1.2.13 folder)
from pyquery import *
Done.
I'm using miniconda on Windows and here is how I installed pyQuery :
Download python miniconda from http://conda.pydata.org/miniconda.html
(if you need many libraries at once, consider installing anadonda instead)
Then from the commandline prompt, run the following commands:
conda install lxml
conda install setuptools
Grab the lastest pyQuery source from https://codeload.github.com/gawel/pyquery/zip/master and unzip it to a directory.
Again from the commandline, go to this directory and run :
python setup.py install