How to read a (static) file from inside a Python package?

TLDR; Use standard-library’s importlib.resources module as explained in the method no 2, below. The traditional pkg_resources from setuptools is not recommended anymore because the new method: it is significantly more performant; is is safer since the use of packages (instead of path-stings) raises compile-time errors; it is more intuitive because you don’t have to “join” … Read more

What is the difference between require() and library()?

There’s not much of one in everyday work. However, according to the documentation for both functions (accessed by putting a ? before the function name and hitting enter), require is used inside functions, as it outputs a warning and continues if the package is not found, whereas library will throw an error.

“pip install unroll”: “python setup.py egg_info” failed with error code 1

About the error code According to the Python documentation: This module makes available standard errno system symbols. The value of each symbol is the corresponding integer value. The names and descriptions are borrowed from linux/include/errno.h, which should be pretty all-inclusive. Error code 1 is defined in errno.h and means Operation not permitted. About your error … Read more

How to fix “Attempted relative import in non-package” even with __init__.py

To elaborate on Ignacio Vazquez-Abrams’s answer: The Python import mechanism works relative to the __name__ of the current file. When you execute a file directly, it doesn’t have its usual name, but has “__main__” as its name instead. So relative imports don’t work. You can, as Igancio suggested, execute it using the -m option. If … Read more

How should I deal with “package ‘xxx’ is not available (for R version x.y.z)” warning?

1. You can’t spell The first thing to test is have you spelled the name of the package correctly? Package names are case sensitive in R. 2. You didn’t look in the right repository Next, you should check to see if the package is available. Type setRepositories() See also ?setRepositories. To see which repositories R … Read more