setuptools not found when installing local package in development mode with pip

Question:

I am developing a Python package, and would like to install it in development mode using pip. When I run pip install, I get a ModuleNotFoundError telling me that setuptools is missing:

$ pip install -e my-package/
...
  Running setup.py develop for my-package
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/user/my-package/setup.py'"'"'; __file__='"'"'/home/user/my-package/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix=
         cwd: /home/user/my-package/
    Complete output (3 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'setuptools'

This confuses me, as I do indeed have setuptools:

$ sudo apt-get install python3-setuptools
[sudo] password for user: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-setuptools is already the newest version (45.2.0-1).
The following packages were automatically installed and are no longer required:
  espeak-ng-data gir1.2-gstreamer-1.0 libao-common libao4 libaudio2 libdotconf0 libespeak-ng1
  libfprint-2-tod1 libllvm9 libllvm9:i386 libpcaudio0 libsonic0 libspeechd2 python3-brlapi python3-click
  python3-colorama python3-louis python3-pyatspi python3-speechd sound-icons
  speech-dispatcher-audio-plugins xbrlapi
Use 'sudo apt autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 231 not to upgrade.

and I can import it without error in regular python:

$ python
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> 

I can even invoke the exact part of the command that’s giving an error without getting any error myself!

$ /usr/bin/python -c 'import io, os, sys, setuptools, tokenize'
$

Why doesn’t pip find setuptools? It’s also worth noting that pip install my-package works without the -e flag for development mode.

My python/pip executables:

$ which python
/usr/bin/python            [a symlink to /usr/bin/python3.9]
$ which python3
/usr/bin/python3           [a symlink to /usr/bin/python3.8]
$ which pip
/home/user/.local/bin/pip
$ which pip3
/home/user/.local/bin/pip3
Asked By: Danica Scott

||

Answers:

I had this issue previously and the following steps worked for me.

  1. Install setuptools using pip.
    Pypi page: https://pypi.org/project/setuptools/.

    python -m pip install setuptools
    
  2. Verify that setuptools is installed.

    python -m pip list
    

    enter image description here

  3. Attempt to re-install your package again.

    python -m pip install -e my-package/
    
Answered By: Raymond C.

Executing this:

sudo python setup.py develop

from the package directory worked in the end. I can’t explain why the other methods didn’t work, but this was a workaround for my problem.

Answered By: Danica Scott

If nothing is working, only if…

Upload your code to GitHub and install from there.
This worked for me.

Install it like this:

pip install git+https://github.com/sarimbinwaseem/rsimageconvertor.git@main
pip install git+<link to repo.git>@<branch>
Answered By: Sarim Bin Waseem
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.