Search code examples
pythonpython-3.xpipwaitress

Waitress installed via pip, but cannot be executed


Overall, pip is working fine on my server. I have just installed the package waitress and the installation seems successful. I checked it with pip freeze:

$ pip freeze | grep waitress
waitress==2.1.0

Waitress also can be imported via python3:

>>> import waitress
>>>

However, waitress-serve cannot be executed:

$ waitress-serve
Command 'waitress-serve' not found, but can be installed with:
apt install python3-waitress
Please ask your administrator.

I am not a root user on this server. Could this be a reason why the package was installed partially, or am I speculating here?

Since I am not authorized to run apt install and since the simple pip install worked in my virtualenv, I would like to be able to get this to work without using the suggested apt install python3-waitress command.


Solution

  • The conclusion is that, while it is installed both inside and outside virtualenv, it is only actually executable inside it.

    When installable Python packages give you an actual entry point, generally it will not be on your path.

    When you use a virtual environment, activating the environment puts various parts of that environment onto the path temporarily. This is intended to ensure that commands like python or python3 run the environment's Python, but it also allows those entry points to be found on the path.

    A system Python installation (here I mean, not just a Python that comes with your operating system, but also one that you install manually after the fact - but not a virtual environment) will generally not have its library folders on the path by default - only enough to make python and pip work. (On Windows, often even these are not added to the path; instead, a program py is placed in the Windows installation folder, and it does the work of looking for Python executables.) Even if you are allowed to install things directly into a system Python (and you should normally not do this if you can avoid it, even if you're allowed to), they won't be findable there.

    Of course, you could execute these things just fine by explicitly specifying their paths. However, the normally correct approach is to just ensure that, when you want to run the program, the same virtual environment is activated into which you installed the package.

    (On my system, I have one main "sandbox" virtual environment that I use for all my projects - unless I am specifically testing the installation process, or testing how the code works on a different version of Python. Then I use a wrapper script to open a terminal window, navigate to a folder that contains all my projects, and activate the environment.)