Why doesn't Python 3 find installed packages (e.g. BeautifulSoup4)? - python

Using Ubuntu 16.04 with Python 3.5 I get import errors for some packages, e.g. 'BeautifulSoup4' or 'requests'. Both libraries are installed from the Ubuntu repositories:
$ dpkg --get-selections | grep -E "python3-req|python3-bs"
python3-bs4 install
python3-requests install
Yet I get "ImportError: no module named 'bs4'/'requests'".
$ python3 -c "import bs4"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'bs4'
Only when I (additionally!) install those libraries via pip3 it works. The documentation of BeautifulSoup says to install it as "python3-bs4" via apt. Why does it only work with the pip3 method? What's the purpose of the python3-bs4/python3-requests packages?

I was able to resolve the issue.
I'm still not quite sure what was the exact problem, but I suspect that pip3 and apt confused each other about what was actually installed. pip3 also listed several python packages which were installed via apt.
I removed/purged everything via apt that was recognized by pip3 list and also purged pip3. Then I apt install --reinstall the packages that gave me trouble previously: python3-bs4 and python3-requests. The requests library still didn't work because it missed the packages python3-six, python3-chardet and python3-urllib3 which where reported as already installed by apt. A apt install --reinstall fixed this as well. And then it worked!

Related

System PIP seems broken after I tried to upgrade it on my Big Sur / Apple silicon Macbook

It seems like I messed up the system pip by pip3 install --upgrade pip. Actually I even do not exactly remember whether I did upgrade or not.
Now when I try to use pip3, it gives an error like
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/usr/bin/pip3", line 6, in <module>
from pip._internal import main
ImportError: cannot import name 'main' from 'pip._internal' (unknown location)
I tried sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall to revert back PIP by this answer, but it fails.
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed
which pip3 gives /usr/bin/pip3
Now I am trying to revert back the system tools and use virtual environment.
What should I do? I can't even check which pip version is installed at the moment.
Thanks in advance.

Why can't I use pip3 after installing pip?

I want to install tensorflow-cpu using pip on my Ubuntu 18.04, 64-bit system and it required pip>=19.0.
I was having pip 9.0.x and was using pip3 to install packages but to fulfill the requirement I ran
pip3 install pip
which installed pip 19.2.3 but after doing it I can no longer use pip3. Using pip3 now gives this error
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
Earlier using pip would give this error
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
but now using it to install packages works totally fine.
I read a lot of articles after which I realised that we use pip for python 2.x and for python 3.x we use pip3. But with the change in behaviour after upgrading pip I'm totally confused and can't find any help. Is using pip to install a package same as installing it using pip3. What are the differences between them?

No module named packaging

I work on Ubuntu 14. I install python3 and pip3.
When I try to use pip3, I have this error
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 70, i
n <module>
import packaging.version
ImportError: No module named 'packaging'
Does someone know what is the issue?
Many thanks
First update your pip version itself. You can take a look at this answer
pip3 install --upgrade pip
And then try to install packaging, if its not already installed by now.
pip3 install packaging
I recently had the same error. Unfortunately none of the other answers solved my problem. Finally installing the following package resolved my issue:
sudo apt install python3-packaging
For older versions of Python you may need to adjust the command:
sudo apt install python-packaging
If I understand well, the issue that causes confusion in other's replies is that you have an error while running pip itself, which prevents self-updates of pip or installation of the missing package.
As requested, please state exactly how you installed Python 3 and pip. Ubuntu 14 does not come with Python 3.5.
For diagnosis, please give the output of
which python3
that is probably /usr/bin/python3 and refers to the system-wide python3 while your pip is located in /usr/local/bin/pip3.
Suggested solution: Uninstall system pip with apt-get remove python3-pip and try again with either pip3 or python3.5 -m pip.
I got this issue and I solved it by getting the path to my python module on my virtualenv
python3.7 -c 'import sys; print(sys.path)'
Then I cloned github repository for Packaging
in one of the directory..
That's about it
I tried all of the above.
I had to manually add the libraries to the pyinstaller command as data:
.\pyinstaller.exe -F --add-data ".\venv\Lib\site-packages\packaging;packaging" --add-data ".\venv\Lib\site-packages\webdriver_manager;webdriver_manager" --onefile .\departed_shipments.py

ImportError: No module named 'appdirs'

I'm trying to get a program called hangoutsbot
to work on my linux server. I'm currently using a digital ocean server. However, every time I try to run the script it gives me an error that says:
ImportError: No module named 'appdirs'
I'm not sure what to do here. I've already tried installing appdirs from npm to no avail. This script works fine on my mac, however it doesn't seem to want to run on my linux server. Any help would be appreciated.
I ran across the same problem after solving the "missing pyparsing module" bug over here. I then started getting this error:
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 74, in <module>
import appdirs
ImportError: No module named appdirs
I then used the manual installation steps there to find the missing package on pypi.python.org and came up with this manual installation sequence:
wget https://pypi.python.org/packages/48/69/d87c60746b393309ca30761f8e2b49473d43450b150cb08f3c6df5c11be5/appdirs-1.4.3.tar.gz
gunzip appdirs-1.4.3.tar.gz
tar -xvf appdirs-1.4.3.tar
cd appdirs-1.4.3
sudo python setup.py install
And that fixed it!
For some reason your pipenv installation is not completely done, maybe if you just uninstall and install all missing packages again, it can works. For example, if you are using a MAC:
sudo pip uninstall <missing packages> and after sudo pip install <missing packages>
In this specific case:
sudo pip uninstall appdirs and sudo pip install appdirs
When you run hangoutsbot you'll need to specifically call the python version that has the modules installed. The following worked for me and I had python3.4 and python3.5 installed.
python3.5 hangoutsbot/hangoutsbot.py -d
I had this issue on Ubuntu 14.04 , which ships with a really old version of pip. I was using python 2.7. Upgrading to a newer version of pip with "pip install --upgrade pip" solved this issue for me. (I did this within my virtualenv, but could be needed at the system level depending on what you are trying to do.)
This was where I discovered the solution:
https://www.reddit.com/r/Python/comments/5pwngp/setuptools_34_has_been_released_and_breaks_with/

ImportError: No module named six

I'm trying to build OpenERP project, done with dependencies. It's giving this error now
Traceback (most recent call last):
File "openerp-client.py", line 105, in <module>
File "modules\__init__.pyo", line 23, in <module>
File "modules\gui\__init__.pyo", line 22, in <module>
File "modules\gui\main.pyo", line 33, in <module>
File "rpc.pyo", line 29, in <module>
File "common\__init__.pyo", line 22, in <module>
File "common\common.pyo", line 26, in <module>
File "tools\__init__.pyo", line 28, in <module>
File "dateutil\relativedelta.pyo", line 12, in <module>
ImportError: No module named six
Could someone guide what's wrong and how it can be fixed???
You probably don't have the six Python module installed. You can find it on pypi.
To install it:
$ easy_install six
(if you have pip installed, use pip install six instead)
If pip "says" six is installed but you're still getting:
ImportError: No module named six.moves
try re-installing six (worked for me):
pip uninstall six
pip install six
For Mac OS X:
pip install --ignore-installed six
On Ubuntu and Debian
apt-get install python-six
does the trick.
Use sudo apt-get install python-six if you get an error saying "permission denied".
pip install --ignore-installed six
Source: 1233 thumbs up on this comment
I did the following to solve the mentioned problem. I got the mentioned problem when I was trying to run the built exe, even I successfully built the exe using pyinstaller. I did this on Windows 10.
go to https://pypi.org/project/six/#files
download "six-1.14.0.tar.gz (33.9 kB)"
unzip it, copy and paste "six.py" into your source directory.
import "six" module into your source code (import six)
run source script.
on Ubuntu Bionic (18.04), six is already install for python2 and python3 but I have the error launching Wammu.
#3ygun solution worked for me to solve
ImportError: No module named six
when launching Wammu
If it's occurred for python3 program, six come with
pip3 install six
and if you don't have pip3:
apt install python3-pip
with sudo under Ubuntu!
In my case, six was installed for python 2.7 and for 3.7 too, and both pip install six and pip3 install six reported it as already installed, while I still had apps (particularly, the apt program itself) complaining about missing six.
The solution was to install it for python3.6 specifically:
/usr/bin/python3.6 -m pip install six
Ubuntu 18.04.5 LTS (Bionic Beaver):
apt --reinstall install python3-debian
apt --reinstall install python3-six
If /usr/bin/chardet3 fails with error "ModuleNotFoundError: No module named 'pkg_resources'":
apt --reinstall install python3-pkg-resources
For me the issue wasn't six but rst2pdf itself. head -1 $(which rst2pdf) (3.8) didn't match python3 --version (3.9). My solution:
pip3 install rst2pdf
six is a Python module. The python command may refer to Python2.
It is possible that you are confusing Python2 and Python3, or that you confused the Python version number this module applies to. six for Python2 is distinct from six for Python3.
If installing six still does not work via pip, consider running Python3 instead.
For Ubuntu and Debian
Try to execute the following command-
sudo apt install python-six
If it's not working perfectly then try to force it by using the following command-
/usr/local/bin/pip3 install six
I hope it works!

Categories