How do I get python requests package to work? - python

I can't seem to get the requests package to install correctly. Regardless of what I use to actually run my program, I get the same error:
Traceback (most recent call last): File "/Users/garce/Desktop/songlyrics/getlyrics.py", line 2, in <module> import requests ModuleNotFoundError: No module named 'requests'
However, I've used pip to install requests. When I run pip show requests in a terminal window, it comes up with this:
Name: requests Version: 2.24.0 Summary: Python HTTP for Humans. Home-page: https://requests.readthedocs.io Author: Kenneth Reitz Author-email: me#kennethreitz.org License: Apache 2.0 Location: /Users/garce/opt/anaconda3/lib/python3.8/site-packages Requires: urllib3, idna, certifi, chardet Required-by: Sphinx, jupyterlab-server, conda, conda-build, anaconda-project, anaconda-client
I assume this is a path issue of some sort, but I can't figure out what's going wrong here. Any idea?

Are you installing the package globally, or within a pipenv environment? If globally, have you tried pipenv? Not only is it considered best practices, but I find that using pipenv or Anaconda environments often resolves path issues I experience.

Related

How to use python packages from given directory, other than default directory?

Let's say I've installed torch using pip3 in my user1's account.
user1#desktop:~$ pip3 show torch
Name: torch
Version: 1.11.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages#pytorch.org
License: BSD-3
Location: /home/user1/.local/lib/python3.8/site-packages
Requires: typing-extensions
Required-by: ogb, pytorch-lightning, torchaudio, torchmetrics, torchvision
As can be seen above, pip3-installed packages' location is /home/user1/.local/lib/python3.8/site-packages.
Now, say that I want to run some python file using sudo privilege. (Assume that I can pass along the correct password when using sudo privilege.) In this case, however, it returns ModuleNotFoundError since torch is installed in my user1's account, not in root user's.
user1#desktop:~$ sudo python3 toy_example.py
Traceback (most recent call last):
File "toy_example.py", line 1, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
When I attempt to run certain file with sudo privilege, how can I link python packages installed in ordinary user's account? (e.g., torch, which is installed in /home/user1/.local/lib/python3.8/site-packages in the above example) I think it would be possible if I fix some environment variables, but couldn't figure it out.
#minolee 's comment solved the issue. The following command works fine for me.
sudo PYTHONPATH=/home/user1/.local/lib/python3.8/site-packages python3 toy_example.py
Visit Python - add PYTHONPATH during command line module run for more help.

Python could not find module named chatterbot

I changed my laptop lately, so I've been installing the packages I use. After I've installed chatterbot
C:\Users\aser>pip show chatterbot
Name: ChatterBot
Version: 1.0.4
Summary:
Home-page: None
Author: None
Author-email: None
License: None
Location: c:\users\aser\appdata\roaming\python\python38\site-packages
Requires: chatterbot-corpus, sqlalchemy, python-dateutil, mathparse, nltk, pint, pymongo
Required-by:
And I tried to use it:
from chatterbot import ChatBot
# Code goes here
I got a ModuleNotFound error:
Traceback (most recent call last):
File "c:/Users/aser/Desktop/pyapp01/app.py", line 22, in <module>
from chatterbot import ChatBot
ModuleNotFoundError: No module named 'chatterbot'
Any help?? Or is it installed in a location where it shouldn't be?? But all the other packages are installed in this same location too
There is a dedicated Github repo for Chatterbot, and I found the issue Not able to import chatterbot after successful installation #826.
Several other users had the same problems after installing Chatterbot via pip, so you might want to read the responses the developers gave them.
It seems there are issues with package dependencies and in some cases, de-installation and re-installation in a particular order seemed to have helped.
In general, however, I agree with the comments above that working in the Anaconda environment is much more convenient. I also used "pip" a lot when I started coding but gave up on it after I ran into too many installation issues.
The danger always is that you are creating potentially conflicting environments, and Anaconda saves you from such pitfalls.
Maybe you have the module but you don’t download it.
Juste type :
“pip install chatterbot”
on cmd.
Or if that dont work, try :
“import chatterbot”

ModuleNotFoundError though Python module PyBluez is installed

I am using python3 with the Thonny IDE. My programs are running on a Raspberry Pi 4B.
I tried to install PyBluez on different ways, with pip and with the built-in package installer of Thonny. Every time the installation seemed to work. When I then tried to import the module via import PyBluez I always get this error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pybluez'
But when I try to install it again I get these message, what I think mean, that it is already installed:
Requirement already satisfied: pyserial in /usr/lib/python3/dist-packages (3.4)
And the built-in package installer of Thonny shows me this message:
Installed version: 0.23
Installed to: /home/pi/.local/lib/python3.7/site-packages
Latest stable version: 0.23
Summary: Bluetooth Python extension module
Author: Albert Huang
Homepage: http://pybluez.github.io/
PyPI page: https://pypi.org/project/PyBluez/
Requires: pyobjc-core (<6,>=3.1), pyobjc-framework-Cocoa (<6,>=3.1), gattlib (==0.20150805) ; extra == 'ble'
But I still get the error that there is no module with this name.
I also tried to install the package PySerial on the same ways, but I ran into the same problem as with PyBluez. So it might be a general problem?
I haven't personally worked with that module, but after looking at the GitHub documentation, I can see that the import statement that is used is import bluetooth.
For example, on this page that's what they have
import bluetooth
import bluetooth._bluetooth as bluez
Consider using a different import statement

Python SAML authentication

I'm trying to build a SAML authentication mechanism in Python using the OneLogin module, but I can't even get started. Trying from the example code provided in the docs, I can't even load the package.
This works:
import onelogin
but this gets a ModuleNotFoundError:
>>> from onelogin.saml2.auth import OneLogin_Saml2_Auth
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'onelogin.saml2'
I only managed to get this working on a Linux machine, so hope you're not on windows. Here's what worked for me.
I had to do a seperate install of hte xmlsec-library first:
apt-get install xmlsec1 openssl python-lxml libxmlsec1 libxmlsec1-dev
and then I was able to
pip install python3-saml
and there were no complains anymore.
You need to install Xmlsec first and then python3-saml but if you are on Windows, Xmlsec has some issues but as with python 3.6 and below the problem is solved. Use this link to download the wheel file for your python version https://github.com/mehcode/python-xmlsec/releases
Install the wheel file using
pip install <wheel_file_name>
As with Python 3.7, the only way out is to install xmlsec on a Linux machine as it is not yet supported on Windows.

Python error message "Incompatible library version" libxml and etree.so

Update 2:
the main problem turned out to be a different one from what I had thought it was, and asked for help here. I moved the new question to a new post:
Install custom python package in virtualenv
Update:
ok, so I screwed up my non-virtualenv by accident.
The non-virtualenv (normal bash) I could easily fix by removing the manually installed (via pip) lxml and running
conda install lxml --force
But for some reason, that doesn't work in the virtualenv.
There, running
conda install lxml --force
works without error message, but when I run python and simply say
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named lxml
Any suggestions??
old message:
I'm trying to use virtualenv for my python flask application.
The python code runs perfectly fine without the virtualenv.
I've installed the packages I need in the virtualenv, but I after installing lxml via
pip install lxml
Installing collected packages: lxml
Successfully installed lxml-3.6.0
I get the following error message when running my code:
File "/Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/docx-0.2.4-py2.7.egg/docx.py", line 17, in <module>
from lxml import etree
ImportError: dlopen(/Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/lxml/etree.so, 2): Library not loaded: libxml2.2.dylib
Referenced from: /Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/lxml/etree.so
Reason: Incompatible library version: etree.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0
I have seen other people report similar problems at stackoverflow, and one guy remarked that the problem might related to the virtualenv, but there was no solution.
Once again: The python code runs perfectly fine without virtualenv! But inside virtualenv, I can't get it to work.
I'm using Anaconda Python 2.7 on a Mac.
I'd appreciate any help guys!
I had the same error and stumbled upon this link, after searching for the incompatible library error "libxml2.2.dylib provides version 10.0.0"
Installing libxml2 that worked for me:
brew install libxml2
brew link --force libxml2
Solution that works for me in virtual environment is to force pip to recompile lxml:
pip install lxml --force-reinstall --ignore-installed --no-binary :all:

Categories

Resources