53

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 anyone know what is the issue?

4
  • show code you used to install and to import packaging
    – Andersson
    Commented Feb 14, 2017 at 9:21
  • I didn't install packaging. Do I need to install it?
    – Raouf
    Commented Feb 14, 2017 at 9:26
  • 3
    Yes. pypi.python.org/pypi/packaging. Install using pip3 install packaging Commented Feb 14, 2017 at 9:35
  • How did you install python3 and pip3 ?
    – Antwane
    Commented Feb 14, 2017 at 11:21

7 Answers 7

69

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
2
  • It worked for me. Using pip 21.0.1, python 3.8.5, in a win 10. Commented Feb 10, 2021 at 14:45
  • This helped me. Had the same issue with slightly different error No module named 'packaging.metadata'
    – wowkin2
    Commented Jun 25 at 19:10
16

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
5

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.

5
  • Here is python installation script:
    – Raouf
    Commented Feb 14, 2017 at 12:54
  • sudo add-apt-repository ppa:fkrull/deadsnakes sudo apt-get update sudo apt-get install python3.5
    – Raouf
    Commented Feb 14, 2017 at 12:54
  • pip installation sudo apt-get -y install python3-pip
    – Raouf
    Commented Feb 14, 2017 at 12:56
  • What does which python3 and which pip3 give? The fact that the location /usr/local/bin/pip3 appears in your error hints at a non-system install. Can you also give ls /usr/local/bin? Commented Feb 14, 2017 at 13:02
  • It solve my issue. When I use pip3, the program try to use python3.4. By using python3.5 -m pip ... (instead pip3) it works well. Many thanks!
    – Raouf
    Commented Feb 14, 2017 at 13:03
2

For python 3.11, pip 24, archlinux what got it running for me was:

pip install wheel

This was from a virtual environment. Both packaging and setuptools were already installed correctly. This has been easily reproducible within a virtual environment for the past year or so, but it's still unclear what the root cause is.

1

switching to pip==23.0 solved the issue with packaging not being recognized as a module, initially I was working with pip==23.3.2.

0

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

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.