WHY ARE VIRTUAL ENVIRONMENTS NEEDED?
TROUBLESHOOTING!
Working with Python on a pure command-line level is hairy. Modern Python apps include a vast ecosystem of third-party libraries. As with Windows applications, these third-party libraries are developed independently of the application code hosted in users’ workstations. Given that library development often leads to
Nvidia drivers are a fickle bunch. If the first execution of Stable Diffusion works, consider yourself extraordinarily lucky. Usually, various problems occur.
API breaks, keeping a Python program working can become difficult over time. If multiple Python programs are hosted on the same workstation, conflict about library versions is inevitable. The situation gets quixotic if Python is used for system tasks – common in modern Linux environments.
Firstly, be aware of the command-line utility Nvidiasmi. It provides a taskmanager-like overview of things happening, and works especially well when combined with watch .
The Python community’s workaround for this is the virtual environment; think of it as an installation of Python and the library collection dedicated to only one application. In this way, every individual program finds its preferred Python environment and can be run without issues. On the other hand, as you’d expect, hosting multiple virtual environments does come with a price in terms of storage used.
Two error messages are common. Firstly, the message ‘RuntimeError: CUDA error: all CUDAcapable devices are busy or unavailable’. It usually indicates that the graphics accelerator is blocked by another process. Use Nvidiasmi to look for any process marked E and terminate it. Sometimes, simply running the script again two or three seconds later can fix the problem. Errors along the lines of ‘UserWarning: CUDA initialization: CUDA unknown error – this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_ DEVICES after program start. Setting the available devices to be zero’ are insidious. They are caused by an interaction between the suspend system of Linux and the GPU drivers – Nvidia’s driver code is notoriously unhappy about having to resume work after hibernation. If this is the case on your machine, a reboot, login and execution of the script usually fixes the problem. A detailed discussion of the problem can also be found at: https:// bit.ly/lxf302cuda.