from lxml.html import fromstring module not found, lxml installed - python

I am trying to import from lxml.html import fromstring in VSCode but I am getting the error: ModuleNotFoundError: No module named 'lxml' I have installed lxml with pip install lxml
I am using a virtual environment and VS code
Version: 1.52.1 (user setup)
OS: Windows_NT x64 10.0.18363
My python version is 3.7.4 and I forced a reinstall of the wheel file
https://files.pythonhosted.org/packages/7f/7e/e74f03e6e56184f8af8e33055223cb1d8ecec91a7084ca626b8070b2c67f/lxml-4.6.2-cp37-cp37m-manylinux2014_aarch64.whl
This did not solve the issue, and the 32bit wheel version wont work on my 64 bit machine.
The only solutions I could find were the install from wheel and also try the 32bit version.

VS Code shows that the module cannot be found because there is no such module in the currently selected Python environment, Please refer to the following command to check the module:
Please use the command "pip --version" in VS Code to check whether the Python currently used in the terminal is consistent with the Python displayed in the lower left corner of VS Code:
If it is inconsistent, please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, then it will automatically enter the selected Python environment (Python shown in the lower left corner).
We can use the command "pip show lxml" to check its installation location:
Run:
Reference: Python environment in VS Code.

Thank You #JillCheng I resolved the issue by deleting the PATH variable I had in the system environment - it was being used with VScode and conflicting with the virtual environment.

Related

No module named 'odf' due to wrong Python version

I have many different versions of Python, but a version that I use and that terminal show me if use command Python – version is 3.10.0.
When I use command pip list I got a big list of library, including the one I recently installed odfpy.
I open VsCode, choose Python version 3.10.0 and try to import odf but...
ModuleNotFoundError: No module named 'odf'
For sure I need to set something on VsCode or change some configuration in Linux but I cannot find a normal explanation of how to solve this issue.
If I change the Python version in VsCode with 3.8.10, odfpy (and also Django just installed) is recognized. So I suppose that, even if the Python version selected on the terminal is 3.10.0, when I pip install something, is installed on version 3.8.10. How do you manage this?
Please check which pip you are using through the command of pip --version.
After you switch the python interpreter in the VSCode, please create a new terminal, and make sure it has activated the environment you have selected.
I also use VS code and use Python 3.10 and i had try to download the odfpy which has gone alright, i use the command python -m pip install odfpy
try and see if it work for you though.
If it does not work, maybe try and create a virtual environment if you haven't created it yet.
In my case i was getting same error while using import-export django module. Installing odf library didn't worked got same error. I resolve this issue by simply pip install tablib==0.14.0.

Issues importing libraries

I just installed Python and Visual Studio code on a Windows 10 machine.
I have imported i few libraries using pip. When I did that I got a warning saying I needed to add a certain folder to PATH which I did.
Using the cdm, I can start a python environment and import matplotlib without issues. I note that my Python version in the cmd is Python 3.9.7
When doing the same thing in Visual Studio code I get the following error message
ModuleNotFoundError: No module named 'matplotlib'
I also notice that my Pyhton version in Visual Studio Code is Pyhton 3.9.1.
I dont really understand what is going on here since I've never had this issue before. Usually it "just works"
Thanks
You have 2 versions of python installed. One of them could be a virtual environment. You can diagnose which Python interpreter you are using by running:
import sys
print(sys.executable)
If VSCode you can switch between interpreters; it may take some searching through the options.
In to the visual code terminal, which probably is using your venv (you should see "(venv)" at begin of each row) type:
pip list
and look if you module is installed. Otherwise you can install here or change environment.
You have installed in two python versions Python 3.9.7 and Python 3.9.1 in vs code.Matplotlib was installed in Python 3.9.7 in vscode, but you used python3.9.1 as an interpreter, that’s why it threw No module error. You need to add a virtual environment of Python 3.9.1. Python has a full guide here on how to set virtual environment How to add virtual environment
then you change python interpreter
matplotlib has been installed in the python 3.9.7 while not in the python 3.9.1.
So you can try to switch the python version in the VSCode to the python 3.9.7 or install the matplotlib in the python 3.9.1.
You can click here to switch the environment. And you can refer to the official docs for more methods and details.
Or you can install the matplotlib package again in the VSCode terminal.

how to clear unresolved import 'cv2' error?

I have installed Python 3.9 on my ubuntu 18.04 desktop, i have already installed two libraries using pip3 install
1)opencv-contrib-python
2)opencv-python
Currently i am writing a program in VSCode for which i am importing cv2
I have already default version of python 3.6.9 in my computer. When i use default version as interpreter, program seems to be working fine.But if i switch the interpreter to newly installed python 3.9 , i get an error
ModuleNotFoundError: No module named 'cv2'
please someone who has faced such problem and know how to resolve it help me!!!...
The reason is as you described: it is due to the use of the Python environment.
The module "cv2" is installed in "lib\site-packages\" in python3.6.9, but when we use "python3.9" without the module "cv2" installed, VS Code is in "python3.9" The module could not be found in "lib\site-packages\".
You could use the command "pip3 --version" to check the source of the module installation tool, the module is installed in "lib\site-packages\" here:
When using the command "pip3 show opencv-python" to check its installation location: (...\python\python38\lib\site-packages)
Therefore, if you want to use the module "cv2" in "python3.9", please install it in this environment. In addition, it is recommended that you use a virtual environment, it will be stored in "lib\site-packages" in the folder of the project so that you could check it more intuitively.

Installing XLWings with Anaconda with Packages

I have a fresh Anaconda installation (2019.07) for Windows with xlwings version 0.15.8. When I run from RunPython in VBA and try to import numpy I get the following error:
ImportError: DLL load failed: The specified module could not be found.
However when I go to my conda prompt and run python I can import numpy without issue.
The latest version seems to have added a Conda Base configuration variable but I haven't had luck getting it work. The only way I can get it to find pythonw is to use Interpreter variable instead of Conda Base, but that does not find the packages like numpy above.
How do I set the xlwings.conf properly to find my conda install C:\anaconda3, all of the conda packages (like numpy) and my src tree C:\[blah]\src in Windows?
As of Nov 19, 2020
Installing Python using Anaconda version 2020.11.
xlwings comes pre-installed with version 0.20.8 for Windows 32/64 bit and Mac osx-64
This might help anyone else struggling to get set up.

Receiving 'ImportError: cannot import name etree' when using lxml in Python on Mac

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.

Categories

Resources