Cannot import 'etree' from 'lxml' - installation

I have installed lxml on my Windows machine using
pip install lxml
However, if I run
from lxml import etree
or
from requests_html import HTMLSession
I get
cannot import name 'etree' from 'lxml' (C:\Users\user\AppData\Local\Programs\Python\Python39\Lib\site-packages\lxml\__init__.py)
I have uninstalled and reinstalled lxml many times through pip and it installs successfully every time. I can see folders lxml and lxml-4.6.2.dist-info getting installed in site-packages every time I reinstall. I don't have any lxml.py files in this directory either.

Do you also have Anaconda installed ? If you have both Python and Anaconda installed, there are two directories for the site-packages (one for Python and another for Ananconda), which could cause an error when trying to import.
You can try the following steps below and then run your program again:
Uninstall Anaconda from your machine
pip uninstall lxml
pip install lxml

Related

No module named pymc3

HI i'm trying to import pymc3 after pip installing it from the command line within the library where Python.exe sits in. (i.e. >>python -m pip install pymc3). after checking the Lib/Site-Packages library, there's no pymc3, but there is a theanos package installed though. i've looked everywhere for the pymc3 package but can't find it. i've tried installing pymc4 and same thing happens. any idea why?
You should be able to run pip straight for command line.
IE: the command is "pip install pymc3"
Then you would need to import it.
Your issue might also be that you recently installed python and have pip3 installed and not pip. You can check if pip vs pip3 is installed with pip --version and pip3 --version.
Whichever one of those responds with some form of pip XX.X.X from /.... would be the command you need to run.
If you do have pip3 then the command to run from the command line would be "pip3 install pymc3"
Are you able to do
import pymc3
in a Python script? If so, you can find out where it's installed with
print(pymc3.__file__)

Import Error : C Extension while generating windows executable of a Python script using PyInstaller

Import error: C extension: NO MODULE NAMED TIMEDELTAS NOT BUILT. If you want to import PANDAS from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
I tried following things up to now but couldn't resolve this :
pip install --upgrade pip
pip install --upgrade pandas
uninstalled the existing version of pandas and installed again.
pip install Cython
Please look at the SCREENSHOT ATTACHED ABOVE SHOWS VERSION of PANDAS, NUMPY, PYTZ, SIX installed on my system.
NOTE : I'm using Python 2.7
Any help on this will be appreciated.
Thanks.

How do I install a missing Python dependency that is already a system package (and detected by pip install)?

I installed Python/pip with Homebrew, then installed Pandas with pip. However, when I import Pandas, it says there is a missing dependency "pytz".
So I run
pip install pytz
But it thinks it already exists
Requirement already satisfied: pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Removing pytz does not work, when I run pip uninstall pytz, I get permission errors. How should I handle this?
For those interested: I re-installed python/pip with brew again and got this working. Even though Python and pip were in the right directory (/usr/local/bin), Pip was still looking for dependencies in /System. Pip stopped looking in /System after the reinstallation.

Python can't find or install lxml

In Win7, in python 3.4, in pandas, I tried to run pd.read_html.
It aborted, saying it couldn't find lxml.
I added "import lxml", and it said there was no module by that name.
I ran "pip install pandas lxml", and it aborted, saying
C:\Python34\hsf\pandas>pip install pandas lxml
Requirement already satisfied (use --upgrade to upgrade): pandas in c:\python34\
lib\site-packages
Downloading/unpacking lxml
Running setup.py (path:C:\Users\Windows\AppData\Local\Temp\pip_build_Windows\l
xml\setup.py) egg_info for package lxml
Building lxml version 3.4.4.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,
\r\noperable program or batch file.\r\n"
** make sure the development packages of libxml2 and libxslt are installed *
*
I tried pip to install libxml2, and libxslt, and that aborted saying:
C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option:
'bugtrack_url'
warnings.warn(msg)
error: Unable to find vcvarsall.bat
Prior SO answers to similar questions said "use sudo..." so were inapplicable to windows.
How can I install lxml in python 3.4 on Win7 ?
You can try the following:
pip install lxml
For the vcvarvasall.bat you can try installing: https://www.microsoft.com/en-us/download/details.aspx?id=44266
If none of those work you can download the precompiled binary here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
The last option is the easiest. Here are the steps:
1) Download the wheel at http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
2) pip install wheel
3)pip install "path to where you downloaded the *.whl from step 1"

how to cleanly uninstall my python packages with pip3 or any other way?

this is my setup.py file for installing my python program, after the installation using python3 setup.py install an entry to my program was created named testmain , when i did pip3 freeze it showed abc==0.1 in its output ,so i uninstalled it using pip3 with pip3 uninstall abc , though the packages were uninstalled but there still existed the entry testmain on my path , is there a way that pip3 also removes this entry during the uninstall or any other way that i can cleanly uninstall my programs under same scenario ?
from setuptools import setup
setup(name='abc',
version='0.1',
description='test',
url='http://github.com/rjdp',
author='rajdeep',
author_email='rajdeep.sharma#rtcamp.com',
license='MIT',
packages=['cli'],
install_requires=[
'cement',
],
entry_points = {
'console_scripts': ['testmain=cli.abc:main'],
},
zip_safe=False)
Instead of python3 setup.py install use:
pip3 install .
then
pip3 uninstall abc
This will remove testmain.
I had the same question today and spent the entire morning trying to figure out why the script wouldn't uninstall. Nothing worked until I saw Ramana's answer here: https://askubuntu.com/questions/38692/how-does-one-remove-applications-installed-through-python-setup-py-install
"You should always install Python apps with "pip". pip supports uninstall option." and the example in the commment on how local path is supported.

Resources