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('"'"'\r\n'"'"', '"'"'\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